2025-07-01 13:32:55: merge [main:6491e79afd06cd665731c89f8ab2cd373351c1b4];

This commit is contained in:
txix committed 2025-07-01 13:32:55 +03:00
1 parent f699aefa58
commit 264b438cdb
12 files changed
+161 -94

No files matched your search

+2 -2
View File
@@ -10,8 +10,8 @@ import (
)
type AdminMethodStore interface {
IsInnerEndpoint(path string) bool
RequiredAdminPermission(path string) (string, bool)
IsInnerEndpoint(endpoint string) bool
RequiredAdminPermission(endpoint string) (string, bool)
}
type AdminAuthorizer interface {
+16 -16
View File
@@ -1,37 +1,37 @@
package middleware
import (
"net/http"
"strings"
"github.com/pkg/errors"
"github.com/txix-open/isp-kit/log"
"isp-gate-service/request"
"net/http"
)
type EntryPointConfig struct {
PathPrefix string
WithPrefix bool
IsGrpcPath bool
}
func Entrypoint(maxReqBodySize int64, next Handler, logger log.Logger, cfg EntryPointConfig) http.Handler {
type EndpointResolver interface {
ResolveEndpoint(path string, cfg EntryPointConfig) string
}
func Entrypoint(
maxReqBodySize int64,
next Handler,
cfg EntryPointConfig,
entryPointResolver EndpointResolver,
logger log.Logger,
) http.Handler {
return http.HandlerFunc(func(writer http.ResponseWriter, req *http.Request) {
req.Body = http.MaxBytesReader(writer, req.Body, maxReqBodySize)
ctx := request.NewContext(req, writer, getEndpoint(req, cfg))
endpoint := entryPointResolver.ResolveEndpoint(req.URL.Path, cfg)
ctx := request.NewContext(req, writer, endpoint)
err := next.Handle(ctx)
if err != nil {
logger.Error(req.Context(), errors.WithMessage(err, "uncaught error"))
}
})
}
func getEndpoint(req *http.Request, cfg EntryPointConfig) string {
if cfg.WithPrefix {
return req.URL.Path
}
if cfg.IsGrpcPath {
cfg.PathPrefix += "/"
}
return strings.TrimPrefix(req.URL.Path, cfg.PathPrefix)
}