Slim

Slim

type HandlerFunc

type HandlerFunc func(c Context) error

HTTP request handler function signature.

type ErrorHandlerFunc

type ErrorHandlerFunc func(c Context, err error)

Error handler function signature.

type MiddlewareFunc

type MiddlewareFunc func(c Context, next HandlerFunc) error

Request middleware function signature.

type MiddlewareRegistrar

type MiddlewareRegistrar interface {    // Use registers middleware    Use(middleware ...MiddlewareFunc)    // Middleware returns all registered middleware    Middleware() []MiddlewareFunc}

Middleware registrar interface.

type MiddlewareComposer

type MiddlewareComposer interface {    // Compose merges all registered middleware into one middleware    Compose() MiddlewareFunc}

Middleware composer interface.

type MiddlewareConfigurator

type MiddlewareConfigurator interface {    // ToMiddleware converts the instance to a middleware function    ToMiddleware() MiddlewareFunc}

Middleware configurator interface.

type Renderer

type Renderer interface {    Render(c Context, w io.Writer, name string, data any) error}

Renderer is an interface that wraps the Render function.

type Validator

type Validator interface {    Validate(i any) error}

Validator is an interface that wraps the Validate function.

type Map

type Map map[string]any

Simplifies the map[string]any type, less typing required.

func New

func New() *Slim

Returns a basic Slim instance.

type Slim

type Slim struct {    NewContextFunc       func(pathParamAllocSize int) EditableContext // Custom `slim.Context` constructor    ErrorHandler         ErrorHandlerFunc // Custom error handler function    Filesystem           fs.FS            // Static resource filesystem, default value is `os.DirFS(".")`.    Binder               Binder           // Request data binding interface    Validator            Validator        // Validator interface    Renderer             Renderer         // Template renderer    JSONCodec            Codec            // JSON codec    XMLCodec             Codec            // XML codec    Server               *http.Server    TLSServer            *http.Server    Listener             net.Listener    TLSListener          net.Listener    StdLogger            *log.Logger    AutoTLSManager       autocert.Manager    DisableHTTP2         bool    HideBanner           bool    HidePort             bool    ListenerNetwork      string    Debug                bool     // Whether to enable debug mode    MultipartMemoryLimit int64    // File upload size limit    PrettyIndent         string   // json/xml formatting indent    JSONPCallbacks       []string // jsonp callback functions, defaults to []string{"jsonp", "callback"} when created with New    IPExtractor          IPExtractor}

func (*Slim) NewContext

func (s *Slim) NewContext(w http.ResponseWriter, r *http.Request) Context

Creates a context without using the context pool.

func (*Slim) NewRouter

func (s *Slim) NewRouter() Router

Creates a router.

func (*Slim) Router

func (s *Slim) Router() Router

Returns the default router

func (*Slim) Routers

func (s *Slim) Routers() map[string]Router

Returns a host => router mapping collection, excluding the default route.

func (*Slim) RouterFor

func (s *Slim) RouterFor(host string) Router

Returns the router associated with the specified host. If not set, the return value is nil.

func (*Slim) ResetRouterCreator

func (s *Slim) ResetRouterCreator(creator func(s *Slim) Router)

Resets the router creation function.

Warning

This function will immediately recreate the default router and clear all host routers.

func (*Slim) Use

func (s *Slim) Use(middleware ...MiddlewareFunc)

Registers middleware on the Slim instance, implementing the Use method of the MiddlewareRegistrar interface.

func (*Slim) Host

func (s *Slim) Host(name string, middleware ...MiddlewareFunc) Router

Creates a router by providing a host name and middleware functions.

func (*Slim) Negotiator

func (s *Slim) Negotiator() *nego.Negotiator

Returns the content negotiation tool.

func (*Slim) SetNegotiator

func (s *Slim) SetNegotiator(negotiator *nego.Negotiator)

Sets a custom content negotiation tool.

func (*Slim) AcquireContext

func (s *Slim) AcquireContext() Context

Returns an idle slim.Context instance from the context cache pool. When no longer needed, it must be returned by calling the Slim#ReleaseContext method.

func (*Slim) ReleaseContext

func (s *Slim) ReleaseContext(c Context)

Returns a mux.Context instance obtained through Mux.AcquireContext to the context cache pool.

func (s *Slim) ServeHTTP

func (s *Slim) ServeHTTP(w http.ResponseWriter, r *http.Request)

Implements the http.Handler interface.

func ErrorHandler

func ErrorHandler(c Context, err error)

Default error handler function

func NotFoundHandler

func NotFoundHandler(_ Context) error

Default 404 handler

func MethodNotAllowedHandler

func MethodNotAllowedHandler(_ Context) error

Default 405 handler.

Navigate Select esc Close search