2026-02-11 16:56:17: merge [main:afeadb1d9a241da30507f3683781558dbccfefc6];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s

This commit is contained in:
txix committed 2026-02-11 16:56:17 +03:00
1 parent aecc42c6d8
commit d4091f8805
25 files changed
+1664 -92

No files matched your search

+33
View File
@@ -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)
})
}
+36
View File
@@ -0,0 +1,36 @@
package middleware
import (
"context"
"net/http"
"isp-router-service/domain"
http2 "github.com/txix-open/isp-kit/http"
"github.com/txix-open/isp-kit/log"
)
type HttpError interface {
WriteError(w http.ResponseWriter) error
}
func ErrorHandler(logger log.Logger) http2.Middleware {
return func(next http2.HandlerFunc) http2.HandlerFunc {
return http2.HandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
err := next(ctx, w, r)
if err == nil {
return nil
}
logger.Error(ctx, err)
httpErr, ok := err.(HttpError)
if ok {
return httpErr.WriteError(w)
}
return domain.NewHttpError(http.StatusInternalServerError, "internal service error", err).
WriteError(w)
})
}
}