router

package
v0.1.1-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodGet     = "GET"
	MethodPost    = "POST"
	MethodPut     = "PUT"
	MethodDelete  = "DELETE"
	MethodPatch   = "PATCH"
	MethodOptions = "OPTIONS"
	MethodHead    = "HEAD"
	MethodConnect = "CONNECT"
	MethodTrace   = "TRACE"
)

HTTP methods

View Source
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

HandlerFunc is a function type that implements the Handler interface

func (HandlerFunc) HandleRequest

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

MiddlewareFunc is a function type that implements the Middleware interface

func (MiddlewareFunc) Process

Process calls f(ctx, request, next)

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router is the main structure for routing

func NewRouter

func NewRouter() *Router

NewRouter initializes a new Router instance

func (*Router) AddRoute

func (r *Router) AddRoute(method, path string, handler Handler)

AddRoute registers a new route with a handler

func (*Router) HandleRequest

HandleRequest routes the incoming request to the appropriate handler

func (*Router) SetMethodNotAllowedHandler

func (r *Router) SetMethodNotAllowedHandler(handler Handler)

SetMethodNotAllowedHandler sets a custom handler for 405 Method Not Allowed responses

func (*Router) SetNotFoundHandler

func (r *Router) SetNotFoundHandler(handler Handler)

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

Jump to

Keyboard shortcuts

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