MSP-5358 reimplement
This commit is contained in:
1 parent
e56a2b829f
commit
0c2bcc6cfe
8 files changed
+84
-30
No files matched your search
@@ -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 {
|
||||
|
||||
+13
-10
@@ -1,13 +1,10 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
"isp-gate-service/request"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type EntryPointConfig struct {
|
||||
@@ -15,15 +12,21 @@ type EntryPointConfig struct {
|
||||
WithPrefix 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)
|
||||
|
||||
endpoint := req.URL.Path
|
||||
if !cfg.WithPrefix {
|
||||
prefix := fmt.Sprintf("%s/", cfg.PathPrefix)
|
||||
endpoint = strings.TrimPrefix(req.URL.Path, prefix)
|
||||
}
|
||||
endpoint := entryPointResolver.ResolveEndpoint(req.URL.Path, cfg)
|
||||
ctx := request.NewContext(req, writer, endpoint)
|
||||
|
||||
err := next.Handle(ctx)
|
||||
|
||||
Reference in new issue
Block a user