Documentation
¶
Index ¶
- Constants
- type Handler
- type HandlerFunc
- type Middleware
- type MiddlewareFunc
- type Router
- func (r *Router) AddRoute(method, path string, handler Handler)
- func (r *Router) HandleRequest(ctx context.Context, request events.LambdaFunctionURLRequest) (events.LambdaFunctionURLResponse, error)
- func (r *Router) SetMethodNotAllowedHandler(handler Handler)
- func (r *Router) SetNotFoundHandler(handler Handler)
- func (r *Router) UsePost(mw Middleware)
- func (r *Router) UsePre(mw Middleware)
Constants ¶
const ( MethodGet = "GET" MethodPost = "POST" MethodPut = "PUT" MethodDelete = "DELETE" MethodPatch = "PATCH" MethodOptions = "OPTIONS" MethodHead = "HEAD" MethodConnect = "CONNECT" MethodTrace = "TRACE" )
HTTP methods
const ( StatusNotFound = 404 StatusMethodNotAllowed = 405 )
HTTP status codes for default handlers
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler interface {
HandleRequest(ctx context.Context, request events.LambdaFunctionURLRequest) (events.LambdaFunctionURLResponse, error)
}
Handler defines the interface for custom handlers
type HandlerFunc ¶
type HandlerFunc func(ctx context.Context, request events.LambdaFunctionURLRequest) (events.LambdaFunctionURLResponse, error)
HandlerFunc is a function type that implements the Handler interface
func (HandlerFunc) HandleRequest ¶
func (f HandlerFunc) HandleRequest(ctx context.Context, request events.LambdaFunctionURLRequest) (events.LambdaFunctionURLResponse, error)
HandleRequest calls f(ctx, request)
type Middleware ¶
type Middleware interface {
Process(ctx context.Context, request events.LambdaFunctionURLRequest, next Handler) (events.LambdaFunctionURLResponse, error)
}
Middleware defines the interface for middleware
type MiddlewareFunc ¶
type MiddlewareFunc func(ctx context.Context, request events.LambdaFunctionURLRequest, next Handler) (events.LambdaFunctionURLResponse, error)
MiddlewareFunc is a function type that implements the Middleware interface
func (MiddlewareFunc) Process ¶
func (f MiddlewareFunc) Process(ctx context.Context, request events.LambdaFunctionURLRequest, next Handler) (events.LambdaFunctionURLResponse, error)
Process calls f(ctx, request, next)
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router is the main structure for routing
func (*Router) HandleRequest ¶
func (r *Router) HandleRequest(ctx context.Context, request events.LambdaFunctionURLRequest) (events.LambdaFunctionURLResponse, error)
HandleRequest routes the incoming request to the appropriate handler
func (*Router) SetMethodNotAllowedHandler ¶
SetMethodNotAllowedHandler sets a custom handler for 405 Method Not Allowed responses
func (*Router) SetNotFoundHandler ¶
SetNotFoundHandler sets a custom handler for 404 Not Found responses
func (*Router) UsePost ¶
func (r *Router) UsePost(mw Middleware)
UsePost adds a post-route middleware to the router
func (*Router) UsePre ¶
func (r *Router) UsePre(mw Middleware)
UsePre adds a pre-route middleware to the router