diff --git a/assembly/locator.go b/assembly/locator.go index 14e896d..c0f6494 100644 --- a/assembly/locator.go +++ b/assembly/locator.go @@ -71,7 +71,6 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli mux := mux2.NewRouter() for _, location := range locations { - location := location var proxyFunc middleware.Handler enableBodyLog := config.Logging.BodyLogEnable @@ -112,15 +111,12 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli middleware.ErrorHandler(l.logger), ) } - var prefixToTrim *string - if !location.WithPrefix { - prefixToTrim = &location.PathPrefix - } entrypoint := middleware.Entrypoint( config.Http.MaxRequestBodySizeInMb*1024*1024, //nolint:gomnd handler, l.logger, - prefixToTrim, + location.PathPrefix, + location.WithPrefix, ) mux.PathPrefix(location.PathPrefix).Handler(entrypoint) } diff --git a/middleware/entrypoint.go b/middleware/entrypoint.go index d8b8f0a..50f409a 100644 --- a/middleware/entrypoint.go +++ b/middleware/entrypoint.go @@ -10,13 +10,13 @@ import ( "isp-gate-service/request" ) -func Entrypoint(maxReqBodySize int64, next Handler, logger log.Logger, pathPrefix *string) http.Handler { +func Entrypoint(maxReqBodySize int64, next Handler, logger log.Logger, pathPrefix string, withPrefix bool) http.Handler { return http.HandlerFunc(func(writer http.ResponseWriter, req *http.Request) { req.Body = http.MaxBytesReader(writer, req.Body, maxReqBodySize) endpoint := req.URL.Path - if pathPrefix != nil { - prefix := fmt.Sprintf("%s/", *pathPrefix) + if !withPrefix { + prefix := fmt.Sprintf("%s/", pathPrefix) endpoint = strings.TrimPrefix(req.URL.Path, prefix) } ctx := request.NewContext(req, writer, endpoint)