Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var HTTPMethods = []string{ http.MethodGet, http.MethodHead, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, http.MethodConnect, http.MethodOptions, http.MethodTrace, }
Functions ¶
func InfraEncoderOpt ¶
func InfraEncoderOpt(middles ...any) transport.ServiceOption
Types ¶
type InfraEncodeMiddle ¶
type InfraEncodeMiddle func(w http.ResponseWriter)
var InfraCORS InfraEncodeMiddle = func(w http.ResponseWriter) {
w.Header().Set("Access-Control-Allow-Origin", "*")
}
type InfraResponseEncoder ¶
type InfraResponseEncoder struct {
Middles []InfraEncodeMiddle
}
func (*InfraResponseEncoder) Encoder ¶
func (re *InfraResponseEncoder) Encoder() transhttp.EncodeResponseFunc
type Middle ¶
var CORS Middle = func(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodOptions { h.ServeHTTP(w, r) w.Header().Set(echo.HeaderVary, echo.HeaderOrigin) w.Header().Set(echo.HeaderAccessControlAllowOrigin, "*") return } w.Header().Set(echo.HeaderVary, echo.HeaderOrigin) w.Header().Add(echo.HeaderVary, echo.HeaderAccessControlRequestMethod) w.Header().Add(echo.HeaderVary, echo.HeaderAccessControlRequestHeaders) w.Header().Set(echo.HeaderAccessControlAllowOrigin, "*") w.Header().Set(echo.HeaderAccessControlAllowMethods, strings.Join(HTTPMethods, ",")) if v := r.Header.Get(echo.HeaderAccessControlRequestHeaders); v != "" { w.Header().Set(echo.HeaderAccessControlAllowHeaders, v) } }) }
var SetXRequestId Middle = func(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if id := r.Header.Get("X-Request-Id"); id == "" { r.Header.Set("X-Request-Id", strings.ReplaceAll(uuid.NewString(), "-", "")) } h.ServeHTTP(w, r) }) }
func (Middle) MiddleFunc ¶
func (middle Middle) MiddleFunc() func(http.HandlerFunc) http.HandlerFunc
Click to show internal directories.
Click to hide internal directories.