Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7bd042239 | ||
|
|
202fa7035e |
No files matched your search
@@ -74,3 +74,5 @@ package.json
|
|||||||
yarn.lock
|
yarn.lock
|
||||||
|
|
||||||
conf/config_dev.yml
|
conf/config_dev.yml
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
@@ -1,3 +1,8 @@
|
|||||||
|
### v5.9.0
|
||||||
|
* Теперь в зависимоси от `StatusCode` выводится соотвествующий уровень логирования: 400 -> warn, 500 -> error
|
||||||
|
* Исправлен порядок мидлварей, для корректного проброса `requestId`
|
||||||
|
### v5.8.1
|
||||||
|
* Обновлены зависимости
|
||||||
### v5.8.0
|
### v5.8.0
|
||||||
* Изменён resolve для endpoint'ов, теперь используется `lookup` у `github.com/julienschmidt/httprouter`
|
* Изменён resolve для endpoint'ов, теперь используется `lookup` у `github.com/julienschmidt/httprouter`
|
||||||
* Добавлен http метод в запрос авторизации (`system/secure/authorize`)
|
* Добавлен http метод в запрос авторизации (`system/secure/authorize`)
|
||||||
|
|||||||
+4
-2
@@ -107,14 +107,15 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha
|
|||||||
config.Logging.SkipBodyLoggingEndpointPrefixes,
|
config.Logging.SkipBodyLoggingEndpointPrefixes,
|
||||||
config.Logging.EnableForceUnescapingUnicode,
|
config.Logging.EnableForceUnescapingUnicode,
|
||||||
),
|
),
|
||||||
|
middleware.RequestId(),
|
||||||
middleware.ErrorHandler(l.logger),
|
middleware.ErrorHandler(l.logger),
|
||||||
middleware.Authenticate(authentication),
|
middleware.Authenticate(authentication),
|
||||||
middleware.AdminAuthenticate(adminService),
|
middleware.AdminAuthenticate(adminService),
|
||||||
|
middleware.ClientRequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId),
|
||||||
middleware.Authorize(authorization, l.logger),
|
middleware.Authorize(authorization, l.logger),
|
||||||
middleware.AdminAuthorize(adminService),
|
middleware.AdminAuthorize(adminService),
|
||||||
middleware.Throttling(throttlingService),
|
middleware.Throttling(throttlingService),
|
||||||
middleware.DailyLimit(dailyLimitService),
|
middleware.DailyLimit(dailyLimitService),
|
||||||
middleware.RequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId),
|
|
||||||
middleware.Metrics(metricsStorage),
|
middleware.Metrics(metricsStorage),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -128,8 +129,9 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha
|
|||||||
config.Logging.SkipBodyLoggingEndpointPrefixes,
|
config.Logging.SkipBodyLoggingEndpointPrefixes,
|
||||||
config.Logging.EnableForceUnescapingUnicode,
|
config.Logging.EnableForceUnescapingUnicode,
|
||||||
),
|
),
|
||||||
|
middleware.RequestId(),
|
||||||
middleware.ErrorHandler(l.logger),
|
middleware.ErrorHandler(l.logger),
|
||||||
middleware.RequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId),
|
middleware.ClientRequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId),
|
||||||
middleware.Metrics(metricsStorage),
|
middleware.Metrics(metricsStorage),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ require (
|
|||||||
github.com/redis/go-redis/v9 v9.11.0
|
github.com/redis/go-redis/v9 v9.11.0
|
||||||
github.com/stretchr/testify v1.11.1
|
github.com/stretchr/testify v1.11.1
|
||||||
github.com/tomakado/websocketproxy v0.1.0
|
github.com/tomakado/websocketproxy v0.1.0
|
||||||
github.com/txix-open/isp-kit v1.31.5-0.20260123103957-277b5e3d66bf
|
github.com/txix-open/isp-kit v1.64.10
|
||||||
github.com/txix-open/jsonschema v1.3.0
|
github.com/txix-open/jsonschema v1.3.0
|
||||||
golang.org/x/net v0.47.0
|
golang.org/x/net v0.47.0
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090
|
||||||
|
|||||||
@@ -125,8 +125,8 @@ github.com/txix-open/etp/v4 v4.0.1 h1:5VSYgGsvnMz0tvUHsjVWFETI0qWBTCF1O3ARCHaCIg
|
|||||||
github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8=
|
github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8=
|
||||||
github.com/txix-open/grmq v1.9.0 h1:ArDbJJcFX9zXKEcPf49rp9nYiRyGMJxGKJAxdbSsfaM=
|
github.com/txix-open/grmq v1.9.0 h1:ArDbJJcFX9zXKEcPf49rp9nYiRyGMJxGKJAxdbSsfaM=
|
||||||
github.com/txix-open/grmq v1.9.0/go.mod h1:EyFOP17KrwEFOUjR+PH8iH3LCtiN9TSQ8t0ysyk62po=
|
github.com/txix-open/grmq v1.9.0/go.mod h1:EyFOP17KrwEFOUjR+PH8iH3LCtiN9TSQ8t0ysyk62po=
|
||||||
github.com/txix-open/isp-kit v1.31.5-0.20260123103957-277b5e3d66bf h1:in9r7MH1bfohhNt7BaMzshQ0R/LjRtGXh0W6a+tLfFk=
|
github.com/txix-open/isp-kit v1.64.10 h1:lAowLtShBbICZbOWQJ4ptr9LaKKRZ7CE5DBK+7LcLqM=
|
||||||
github.com/txix-open/isp-kit v1.31.5-0.20260123103957-277b5e3d66bf/go.mod h1:GvBsX5p2U3/ugK6PuWANYzSy/4YgawROm3eAKb35G6o=
|
github.com/txix-open/isp-kit v1.64.10/go.mod h1:GvBsX5p2U3/ugK6PuWANYzSy/4YgawROm3eAKb35G6o=
|
||||||
github.com/txix-open/jsonschema v1.3.0 h1:XGuOTg22G7PdqfKypjajM20/i5FyGfFYsJKmheebKi4=
|
github.com/txix-open/jsonschema v1.3.0 h1:XGuOTg22G7PdqfKypjajM20/i5FyGfFYsJKmheebKi4=
|
||||||
github.com/txix-open/jsonschema v1.3.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00=
|
github.com/txix-open/jsonschema v1.3.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00=
|
||||||
github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb h1:UJgT4u/QMv5QHKOQeJ7igShHa36c2/vIRqJiRLdDlf0=
|
github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb h1:UJgT4u/QMv5QHKOQeJ7igShHa36c2/vIRqJiRLdDlf0=
|
||||||
|
|||||||
+10
-2
@@ -50,7 +50,7 @@ func (w *writerWrapper) WriteHeader(statusCode int) {
|
|||||||
w.ResponseWriter.WriteHeader(statusCode)
|
w.ResponseWriter.WriteHeader(statusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Logger( // nolint:gocognit
|
func Logger( // nolint:gocognit,funlen
|
||||||
logger log.Logger,
|
logger log.Logger,
|
||||||
enableRequestLogging bool,
|
enableRequestLogging bool,
|
||||||
enableBodyLogging bool,
|
enableBodyLogging bool,
|
||||||
@@ -125,7 +125,15 @@ func Logger( // nolint:gocognit
|
|||||||
|
|
||||||
fields = append(fields, log.ByteString("response", buf.ResponseBody()))
|
fields = append(fields, log.ByteString("response", buf.ResponseBody()))
|
||||||
}
|
}
|
||||||
logger.Debug(ctx.Context(), "log request", fields...)
|
|
||||||
|
switch {
|
||||||
|
case scSrc.StatusCode() >= http.StatusInternalServerError:
|
||||||
|
logger.Error(ctx.Context(), "log request", fields...)
|
||||||
|
case scSrc.StatusCode() >= http.StatusBadRequest:
|
||||||
|
logger.Warn(ctx.Context(), "log request", fields...)
|
||||||
|
default:
|
||||||
|
logger.Debug(ctx.Context(), "log request", fields...)
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -13,10 +13,28 @@ const (
|
|||||||
requestIdHeader = "x-request-id"
|
requestIdHeader = "x-request-id"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RequestId(forwardClientRequestId bool, forwardReqIdByApp map[int]bool) Middleware {
|
func RequestId() Middleware {
|
||||||
return func(next Handler) Handler {
|
return func(next Handler) Handler {
|
||||||
return HandlerFunc(func(ctx *request.Context) error {
|
return HandlerFunc(func(ctx *request.Context) error {
|
||||||
requestId := requestid.Next()
|
requestId := requestid.Next()
|
||||||
|
|
||||||
|
context := requestid.ToContext(ctx.Context(), requestId)
|
||||||
|
context = log.ToContext(context, log.String("requestId", requestId))
|
||||||
|
|
||||||
|
ctx.SetContext(context)
|
||||||
|
return next.Handle(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ClientRequestId(forwardClientRequestId bool, forwardReqIdByApp map[int]bool) Middleware {
|
||||||
|
return func(next Handler) Handler {
|
||||||
|
return HandlerFunc(func(ctx *request.Context) error {
|
||||||
|
requestId := requestid.FromContext(ctx.Context())
|
||||||
|
if requestId == "" {
|
||||||
|
requestId = requestid.Next()
|
||||||
|
}
|
||||||
|
|
||||||
clientRequestId := strings.TrimSpace(ctx.Request().Header.Get(requestIdHeader))
|
clientRequestId := strings.TrimSpace(ctx.Request().Header.Get(requestIdHeader))
|
||||||
|
|
||||||
logFields := make([]log.Field, 0)
|
logFields := make([]log.Field, 0)
|
||||||
|
|||||||
+6
-9
@@ -105,13 +105,10 @@ func (s *Routes) registerEndpoint(
|
|||||||
PathSchema: descriptor.Path,
|
PathSchema: descriptor.Path,
|
||||||
}
|
}
|
||||||
|
|
||||||
router.HandlerFunc(
|
handler := func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||||
httpMethod,
|
ctx := meta.ToContext(r.Context())
|
||||||
path,
|
// хак для передачи метадаты обратно в код
|
||||||
func(_ http.ResponseWriter, r *http.Request) {
|
*r = *r.WithContext(ctx)
|
||||||
ctx := meta.ToContext(r.Context())
|
}
|
||||||
// хак для передачи метадаты обратно в код
|
router.Handle(httpMethod, path, handler)
|
||||||
*r = *r.WithContext(ctx)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user