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 {
// AllowOriginsFunc is an optional callback to dynamically allow or reject an origin.
// If provided, it takes precedence over AllowOrigins.
AllowOriginsFunc func(string) bool
// AllowOrigins is the list of allowed origins.
// An empty slice or a list containing "*" means all origins are allowed.
AllowOrigins []string
// AllowMethods is the list of allowed HTTP methods.
// An empty slice or a list containing "*" means all methods are allowed.
AllowMethods []string
// AllowHeaders is the list of allowed request headers.
// An empty slice or a list containing "*" means all headers are allowed.
AllowHeaders []string
// ExposeHeaders are the response headers that browsers are allowed to access
// via client-side JavaScript (using XMLHttpRequest or Fetch).
ExposeHeaders []string
// MaxAge is the number of seconds a preflight request can be cached by the client.
MaxAge int
// AllowCredentials indicates whether cookies, authorization headers, and TLS
// client certificates are exposed to the browser.
AllowCredentials bool
// AllowPrivateNetwork indicates whether requests from private network contexts
// are allowed (controlled via the "Private-Network" CORS extension header).
AllowPrivateNetwork bool
// SkipStrictOriginCheck controls how requests without a valid Origin header are handled.
//
// By default, (false), requests missing an allowed Origin are rejected, ensuring strict
// cross-origin enforcement for both preflight (OPTIONS) and non-preflight requests.
//
// If set to true, non-preflight requests (e.g., GET, POST) that do not include an
// Origin header are allowed to pass through to the next handler. This is useful for:
//
// - Same-origin requests (browsers often omit the Origin header)
// - Non-browser clients (curl, Go http.Client, etc.) that do not set Origin
//
// Security note: Setting this to true means requests without Origin are trusted.
// You should only enable it if your API must support same-origin or non-browser clients.
SkipStrictOriginCheck bool
}
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.