add warn log

This commit is contained in:
Синельник Тимур Романович committed 2026-03-18 16:51:06 +03:00
1 parent f5a5e7d8bb
commit b692728cc3
2 files changed
+26 -10

No files matched your search

+12
View File
@@ -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
}
+14 -10
View File
@@ -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)
}
}