server

package
v0.0.1-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 16 Imported by: 0

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

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

func WithConfig(cfg *config.Config) Option

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.NewLogger(), 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 WithHost

func WithHost(host string) Option

WithHost sets the host for the server

func WithIdleTimeout

func WithIdleTimeout(timeout time.Duration) Option

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

func WithMaxJSONBodySize(size int64) Option

WithMaxJSONBodySize sets the max JSON body size for the server

func WithMaxUploadedFileSize

func WithMaxUploadedFileSize(size int64) Option

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 WithPort

func WithPort(port int) Option

WithPort sets the port for the server

func WithReadTimeout

func WithReadTimeout(timeout time.Duration) Option

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

func WithWriteTimeout(timeout time.Duration) Option

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

func New

func New(ctx context.Context, options ...Option) Zero

New creates a new Zero server instance with options

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL