1
0
Fork 0
shezmu/server/server.go

29 lines
432 B
Go
Raw Normal View History

2015-10-27 01:22:45 +00:00
package server
import (
"fmt"
"net/http"
2015-10-27 22:23:39 +00:00
"github.com/localhots/satan/stats"
2015-10-27 01:22:45 +00:00
)
type Server struct {
port int
2015-10-27 22:23:39 +00:00
ss *stats.Server
2015-10-27 01:22:45 +00:00
mux *http.ServeMux
}
2015-10-27 22:23:39 +00:00
func New(port int, ss *stats.Server) *Server {
2015-10-27 01:22:45 +00:00
return &Server{
port: port,
2015-10-27 22:23:39 +00:00
ss: ss,
2015-10-27 01:22:45 +00:00
mux: http.NewServeMux(),
}
}
func (s *Server) Start() {
2015-10-27 22:23:39 +00:00
addr := fmt.Sprintf(":%d", s.port)
s.mux.HandleFunc("/stats.json", s.ss.History)
2015-10-27 01:22:45 +00:00
go http.ListenAndServe(addr, s.mux)
}