diff --git a/middleware/entrypoint.go b/middleware/entrypoint.go index 3b6f671..024ae94 100644 --- a/middleware/entrypoint.go +++ b/middleware/entrypoint.go @@ -18,6 +18,7 @@ type EntryPointConfig struct { type EndpointResolver interface { ResolveEndpoint(method string, path string, cfg EntryPointConfig) (*domain.EndpointMeta, error) + GetPaths(path string, cfg EntryPointConfig) (string, string) } func Entrypoint( @@ -32,6 +33,17 @@ func Entrypoint( endpoint, err := entryPointResolver.ResolveEndpoint(req.Method, req.URL.Path, cfg) if err != nil { + lookupPath, endpoint := entryPointResolver.GetPaths(req.URL.Path, cfg) + logger.Warn( + req.Context(), + "call unknown method", + log.String("pathPrefix", cfg.PathPrefix), + log.String("httpMethod", req.Method), + log.String("originalPath", req.URL.Path), + log.String("lookupPath", lookupPath), + log.String("enpoint", endpoint), + ) + http.Error(writer, err.Error(), http.StatusNotImplemented) return } diff --git a/routes/routes.go b/routes/routes.go index bc6261e..88f91cc 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -59,18 +59,10 @@ func (s *Routes) ReceiveRoutes(ctx context.Context, routes cluster.RoutingConfig } func (s *Routes) ResolveEndpoint(method string, path string, cfg middleware.EntryPointConfig) (*domain.EndpointMeta, error) { - lookupPath := path - if !cfg.WithPrefix { - lookupPath = strings.TrimPrefix(lookupPath, cfg.PathPrefix) - } + lookupPath, metaEndpoint := s.GetPaths(path, cfg) handler, params, _ := s.router.Lookup(method, lookupPath) - metaEndpoint := lookupPath - if !cfg.WithLendingSlash { - metaEndpoint = strings.TrimLeft(metaEndpoint, "/") - } - if handler == nil { if cfg.ErrorOnUnknownEndpoint { return nil, errors.Errorf("unknown endpoint '%s'", lookupPath) @@ -88,6 +80,18 @@ func (s *Routes) ResolveEndpoint(method string, path string, cfg middleware.Entr return &meta, nil } +func (s *Routes) GetPaths(path string, cfg middleware.EntryPointConfig) (string, string) { + lookupPath := path + if !cfg.WithPrefix { + lookupPath = strings.TrimPrefix(lookupPath, cfg.PathPrefix) + } + metaEndpoint := lookupPath + if !cfg.WithLendingSlash { + metaEndpoint = strings.TrimLeft(metaEndpoint, "/") + } + return lookupPath, metaEndpoint +} + func (s *Routes) registerEndpoint( router *httprouter.Router, httpMethod string, @@ -111,4 +115,4 @@ func (s *Routes) registerEndpoint( *r = *r.WithContext(ctx) } router.Handle(httpMethod, path, handler) -} +} \ No newline at end of file