Working server with 5s stats snapshots
This commit is contained in:
+7
-6
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user