package api import ( "context" "net/http" "github.com/kami/hexis/internal/execution" "github.com/kami/hexis/internal/storage" ) type Server struct { handler *Handler httpSrv *http.Server } // NewServer builds the HTTP server. authToken is the shared bearer token // required on /api/v1/; see Handler.requireAuth. func NewServer(store *storage.Store, engine *execution.Engine, authToken string) *Server { handler := NewHandler(store, engine, authToken) return &Server{handler: handler} } func (s *Server) ListenHTTP(addr string) error { mux := http.NewServeMux() s.handler.Register(mux) s.httpSrv = &http.Server{ Addr: addr, Handler: mux, } return s.httpSrv.ListenAndServe() } func (s *Server) Shutdown(ctx context.Context) error { if s.httpSrv != nil { return s.httpSrv.Shutdown(ctx) } return nil }