Working server with 5s stats snapshots

This commit is contained in:
2015-10-28 01:23:39 +03:00
parent 3c77fec5e3
commit bd345af332
4 changed files with 66 additions and 61 deletions
+7 -6
View File
@@ -3,25 +3,26 @@ package server
import (
"fmt"
"net/http"
"github.com/localhots/satan/stats"
)
type Server struct {
port int
ss *stats.Server
mux *http.ServeMux
}
func NewServer(port int) *Server {
func New(port int, ss *stats.Server) *Server {
return &Server{
port: port,
ss: ss,
mux: http.NewServeMux(),
}
}
func (s *Server) Handle(pattern string, handler http.Handler) {
s.mux.Handle(pattern, handler)
}
func (s *Server) Start() {
addr := fmt.Sprintf(":%d", port)
addr := fmt.Sprintf(":%d", s.port)
s.mux.HandleFunc("/stats.json", s.ss.History)
go http.ListenAndServe(addr, s.mux)
}