42 lines
943 B
Go
42 lines
943 B
Go
package http
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
"net/http/pprof"
|
|
|
|
"git.loyso.art/frx/devsim/internal/store"
|
|
)
|
|
|
|
type handlersBuilder struct {
|
|
mux *http.ServeMux
|
|
}
|
|
|
|
func NewHandlersBuilder() *handlersBuilder {
|
|
return &handlersBuilder{
|
|
mux: http.NewServeMux(),
|
|
}
|
|
}
|
|
|
|
// MountStatsHandlers mounts stats related handlers.
|
|
func (h *handlersBuilder) MountStatsHandlers(sr store.Stats, log *slog.Logger) {
|
|
// log = log.With(slog.String("api", "http"))
|
|
// mws := multipleMiddlewares(
|
|
// middlewarePanicRecovery(log),
|
|
// middlewareLogger(log),
|
|
// )
|
|
|
|
h.mux.Handle("/api/v1/stats/", listStatsHandler(sr))
|
|
h.mux.Handle("/api/v1/stats/{id}", postStatsHandler(sr))
|
|
}
|
|
|
|
func (s *handlersBuilder) MountProfileHandlers() {
|
|
s.mux.HandleFunc("/debug/pprof", pprof.Index)
|
|
s.mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
|
|
s.mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
|
|
}
|
|
|
|
func (s *handlersBuilder) Build() http.Handler {
|
|
return s.mux
|
|
}
|