2026-02-11 16:56:17: merge [main:afeadb1d9a241da30507f3683781558dbccfefc6];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
This commit is contained in:
1 parent
aecc42c6d8
commit
d4091f8805
25 files changed
+1664
-92
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"context"
|
||||
"isp-router-service/domain"
|
||||
"net/http"
|
||||
|
||||
http2 "github.com/txix-open/isp-kit/http"
|
||||
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
)
|
||||
|
||||
type Proxy interface {
|
||||
Handle(ctx *domain.RequestContext) error
|
||||
PrepareEndpoint(endpoint string, proxyApiPrefix bool) string
|
||||
}
|
||||
|
||||
func Entrypoint(
|
||||
maxMessageSize int64,
|
||||
proxyApiPrefix bool,
|
||||
proxy Proxy,
|
||||
logger log.Logger,
|
||||
) http2.HandlerFunc {
|
||||
return http2.HandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
|
||||
r.Body = http.MaxBytesReader(w, r.Body, maxMessageSize)
|
||||
|
||||
endpoint := proxy.PrepareEndpoint(r.URL.Path, proxyApiPrefix)
|
||||
reqCtx := domain.NewContext(r, w, endpoint)
|
||||
reqCtx.SetContext(ctx)
|
||||
|
||||
return proxy.Handle(reqCtx)
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user