Add basePath to mux
This commit is contained in:
parent
b62fecf362
commit
28a751db3d
10
server.go
10
server.go
@ -10,19 +10,25 @@ import (
|
||||
|
||||
type Server struct {
|
||||
*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 {
|
||||
mux = http.NewServeMux()
|
||||
}
|
||||
return &Server{
|
||||
ServeMux: mux,
|
||||
basePath: basePath,
|
||||
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) {
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user