Documentation
¶
Index ¶
- func AllowCORS(opts *CORSOptions) func(next http.Handler) http.Handler
- func DumpHttp(level slog.Level, maxBody int64) func(http.Handler) http.Handler
- func MiddlewareSequencer(baseHandler http.Handler, mws ...func(http.Handler) http.Handler) http.Handler
- func PanicCatcher(next http.Handler) http.Handler
- func Timer(level slog.Level) func(http.Handler) http.Handler
- func Tracer(next http.Handler) http.Handler
- type CORSOptions
- type Controller
- type Formatter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllowCORS ¶
func AllowCORS(opts *CORSOptions) func(next http.Handler) http.Handler
AllowCORS sets headers for CORS mechanism supports secure.
func MiddlewareSequencer ¶
func MiddlewareSequencer(baseHandler http.Handler, mws ...func(http.Handler) http.Handler) http.Handler
MiddlewareSequencer chains middleware functions in a chain.
func PanicCatcher ¶
PanicCatcher handles panics in http.HandlerFunc.
Types ¶
type CORSOptions ¶
type CORSOptions struct {
AllowOrigins []string // List of allowed origins.
AllowOriginsFunc func(string) bool // Optional function for dynamic origin matching.
AllowMethods []string // List of allowed HTTP methods.
AllowHeaders []string // List of allowed request headers.
ExposeHeaders []string // List of headers to expose to the client.
MaxAge int // Max age (in seconds) to cache preflight.
AllowCredentials bool // Whether credentials are allowed.
AllowPrivateNetwork bool // Whether requests from private networks are allowed.
}
CORSOptions represents configuration for the CORS middleware.
type Controller ¶
type Controller struct {
Server *http.Server
GracefulTimeout time.Duration
// contains filtered or unexported fields
}
Controller is a wrapper around *http.Server to control the server.
Server — *http.Server, which will be managed. GracefulTimeout — time that is given to the server to shut down gracefully.
func (*Controller) OnStart ¶ added in v0.2.0
func (c *Controller) OnStart(f func(*http.Server))
OnStart registers a callback function that is executed every time the controller starts or restarts. The provided function `f` receives a pointer to the HTTP server managed by the controller, allowing the user to perform custom initialization or configuration tasks at startup.
func (*Controller) Restart ¶
func (c *Controller) Restart()
Restart restarts the server if necessary. For changes to the following parameters to take effect:
Addr; TLSConfig; TLSNextProto; ConnState; BaseContext; ConnContext,
a server restart is required. Other parameters can be changed without restarting the server. If the server is not running, the function will be skipped.
func (*Controller) Shutdown ¶
func (c *Controller) Shutdown()
Shutdown gracefully shuts down the server.
func (*Controller) Start ¶
func (c *Controller) Start() (err error)
Start starts the *http.Server. If *tls.Config on the server is non nil, the server listens and serves using tls.