29 lines
433 B
Go
29 lines
433 B
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/localhots/shezmu/stats"
|
|
)
|
|
|
|
type Server struct {
|
|
port int
|
|
ss *stats.Server
|
|
mux *http.ServeMux
|
|
}
|
|
|
|
func New(port int, ss *stats.Server) *Server {
|
|
return &Server{
|
|
port: port,
|
|
ss: ss,
|
|
mux: http.NewServeMux(),
|
|
}
|
|
}
|
|
|
|
func (s *Server) Start() {
|
|
addr := fmt.Sprintf(":%d", s.port)
|
|
s.mux.HandleFunc("/stats.json", s.ss.History)
|
|
go http.ListenAndServe(addr, s.mux)
|
|
}
|