Skip to content

Commit

Permalink
removed unneeded function
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Koch committed Nov 2, 2022
1 parent 8bb2148 commit 7d3be97
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func New(cmdCtx, evalCtx context.Context, log logrus.FieldLogger, settings *conf
muxersList := make(muxers)
for host, muxOpts := range hosts {
mux := NewMux(muxOpts)
mux.registerHandler(mux.endpointRoot, []string{http.MethodGet}, settings.HealthPath, handler.NewHealthCheck(settings.HealthPath, shutdownCh))
registerHandler(mux.endpointRoot, []string{http.MethodGet}, settings.HealthPath, handler.NewHealthCheck(settings.HealthPath, shutdownCh))

muxersList[host] = mux
}
Expand Down
16 changes: 6 additions & 10 deletions server/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,30 +92,26 @@ func NewMux(options *runtime.MuxOptions) *Mux {

for _, path := range sortedPathPatterns(opts.EndpointRoutes) {
// TODO: handle method option per endpoint configuration
mux.mustAddRoute(mux.endpointRoot, path, opts.EndpointRoutes[path], true)
mustAddRoute(mux.endpointRoot, path, opts.EndpointRoutes[path], true)
}

for _, path := range sortedPathPatterns(opts.FileRoutes) {
mux.mustAddRoute(mux.fileRoot, utils.JoinOpenAPIPath(path, "/**"), opts.FileRoutes[path], false)
mustAddRoute(mux.fileRoot, utils.JoinOpenAPIPath(path, "/**"), opts.FileRoutes[path], false)
}

for _, path := range sortedPathPatterns(opts.SPARoutes) {
mux.mustAddRoute(mux.spaRoot, path, opts.SPARoutes[path], true)
mustAddRoute(mux.spaRoot, path, opts.SPARoutes[path], true)
}

return mux
}

var noDefaultMethods []string

func (m *Mux) registerHandler(root *gmux.Router, methods []string, path string, handler http.Handler) {
func registerHandler(root *gmux.Router, methods []string, path string, handler http.Handler) {
notAllowedMethodsHandler := errors.DefaultJSON.WithError(errors.MethodNotAllowed)
allowedMethodsHandler := middleware.NewAllowedMethodsHandler(methods, noDefaultMethods, handler, notAllowedMethodsHandler)
m.mustAddRoute(root, path, allowedMethodsHandler, false)
}

func (m *Mux) mustAddRoute(root *gmux.Router, path string, handler http.Handler, trailingSlash bool) {
mustCreateNode(root, handler, path, trailingSlash)
mustAddRoute(root, path, allowedMethodsHandler, false)
}

func (m *Mux) FindHandler(req *http.Request) http.Handler {
Expand Down Expand Up @@ -234,7 +230,7 @@ func (m *Mux) getAPIErrorTemplate(reqPath string) (*errors.Template, *config.API
return nil, nil
}

func mustCreateNode(root *gmux.Router, handler http.Handler, path string, trailingSlash bool) {
func mustAddRoute(root *gmux.Router, path string, handler http.Handler, trailingSlash bool) {
if strings.HasSuffix(path, wildcardSearch) {
path = path[:len(path)-len(wildcardSearch)]
if len(path) == 0 {
Expand Down

0 comments on commit 7d3be97

Please sign in to comment.