Documentation
¶
Overview ¶
Package server provides a simple, lean, and blazingly fast HTTP server library. It includes built-in middleware support, graceful shutdown, and a clean API for building HTTP services.
Index ¶
- type Option
- func WithCORS(origins []string, priority middlewares.MiddlewarePriority) Option
- func WithConfig(cfg *config.Config) Option
- func WithDefaultCORS() Option
- func WithDefaultLogging() Option
- func WithDefaultMiddlewares() Option
- func WithDefaultRecovery() Option
- func WithHost(host string) Option
- func WithIdleTimeout(timeout time.Duration) Option
- func WithLogging(logger *slog.Logger, priority middlewares.MiddlewarePriority) Option
- func WithMaxJSONBodySize(size int64) Option
- func WithMaxUploadedFileSize(size int64) Option
- func WithMiddleware(middleware middlewares.Middleware, priority middlewares.MiddlewarePriority) Option
- func WithPort(port int) Option
- func WithReadTimeout(timeout time.Duration) Option
- func WithRecovery(priority middlewares.MiddlewarePriority) Option
- func WithWriteTimeout(timeout time.Duration) Option
- type Zero
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*zero)
func WithCORS ¶
func WithCORS(origins []string, priority middlewares.MiddlewarePriority) Option
WithCORS applies the CORS middleware to the server It applies the CORS middleware to the server with the given allowed origins
func WithConfig ¶
WithConfig sets the config for the server
func WithDefaultCORS ¶
func WithDefaultCORS() Option
WithDefaultCORS applies the default CORS middleware to the server It applies the CORS middleware to the server with the default allowed origins It is equivalent to calling WithCORS([]string{"*"}, middlewares.MiddlewarePriorityLow)
func WithDefaultLogging ¶
func WithDefaultLogging() Option
WithDefaultLogging applies the default logging middlewares to the server It applies the logging middleware to the server with the default logger It is equivalent to calling WithLogging(log.New(), middlewares.MiddlewarePriorityLow)
func WithDefaultMiddlewares ¶
func WithDefaultMiddlewares() Option
WithDefaultMiddlewares applies the default middlewares to the server This is a convenience function that applies the default middlewares to the server It is equivalent to calling WithDefaultLogging(), WithDefaultCORS(), and WithDefaultRecovery() in sequence
func WithDefaultRecovery ¶
func WithDefaultRecovery() Option
WithDefaultRecovery applies the default recovery middleware to the server It applies the recovery middleware to the server It is equivalent to calling WithRecovery(middlewares.MiddlewarePriorityLow)
func WithIdleTimeout ¶
WithIdleTimeout sets the idle timeout for the server
func WithLogging ¶
func WithLogging(logger *slog.Logger, priority middlewares.MiddlewarePriority) Option
WithLogging applies the logging middleware to the server It applies the logging middleware to the server with the given logger
func WithMaxJSONBodySize ¶
WithMaxJSONBodySize sets the max JSON body size for the server
func WithMaxUploadedFileSize ¶
WithMaxUploadedFileSize sets the max uploaded file size for the server
func WithMiddleware ¶
func WithMiddleware(middleware middlewares.Middleware, priority middlewares.MiddlewarePriority) Option
WithMiddleware applies a middleware to the server It applies the middleware to the server with the given middleware and priority
func WithReadTimeout ¶
WithReadTimeout sets the read timeout for the server
func WithRecovery ¶
func WithRecovery(priority middlewares.MiddlewarePriority) Option
WithRecovery applies the recovery middleware to the server It applies the recovery middleware to the server with the given priority
func WithWriteTimeout ¶
WithWriteTimeout sets the write timeout for the server
type Zero ¶
type Zero interface {
Get(pattern string, handler request.Handler, middlewares ...middlewares.Middleware)
Post(pattern string, handler request.Handler, middlewares ...middlewares.Middleware)
Put(pattern string, handler request.Handler, middlewares ...middlewares.Middleware)
Delete(pattern string, handler request.Handler, middlewares ...middlewares.Middleware)
Patch(pattern string, handler request.Handler, middlewares ...middlewares.Middleware)
Handle(pattern string, method string, handler request.Handler, middlewares ...middlewares.Middleware)
Handler() http.Handler
Start() error
Shutdown(ctx context.Context) error
}
Zero is the interface for the Zero server