Add basePath to mux

This commit is contained in:
some 2024-10-02 13:45:42 -04:00
parent b62fecf362
commit 28a751db3d
Signed by: some
GPG Key ID: 65D0589220B9BFC8

View File

@ -10,19 +10,25 @@ import (
type Server struct { type Server struct {
*http.ServeMux *http.ServeMux
Logger log.Logger basePath string
Logger log.Logger
} }
func NewServer(mux *http.ServeMux, logger log.Logger) *Server { func NewServer(mux *http.ServeMux, basePath string, logger log.Logger) *Server {
if mux == nil { if mux == nil {
mux = http.NewServeMux() mux = http.NewServeMux()
} }
return &Server{ return &Server{
ServeMux: mux, ServeMux: mux,
basePath: basePath,
Logger: logger, Logger: logger,
} }
} }
func (s *Server) Handle(pattern string, handler http.Handler) {
s.ServeMux.Handle(s.basePath+pattern, handler)
}
func (s *Server) RegisterCallbackServer(srv server.CallbackServer) { func (s *Server) RegisterCallbackServer(srv server.CallbackServer) {
s.Handle(server.CallbackEndpoint, server.NewServer(server.CallbackRequest{}, []string{http.MethodPost}, s.Logger, func(req server.Request) (res server.Response, errRes server.ErrorResponse) { s.Handle(server.CallbackEndpoint, server.NewServer(server.CallbackRequest{}, []string{http.MethodPost}, s.Logger, func(req server.Request) (res server.Response, errRes server.ErrorResponse) {
callbackRequest, ok := req.(*server.CallbackRequest) callbackRequest, ok := req.(*server.CallbackRequest)