router

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCustomType

func AddCustomType(name, pattern string) error

func BindForm

func BindForm(r *http.Request, v interface{}) error

func BindJSON

func BindJSON(r *http.Request, v interface{}) error

func BindXML

func BindXML(r *http.Request, v interface{}) error

func CSRFMiddleware

func CSRFMiddleware(next http.Handler) http.Handler

CSRF Middleware

func CachingMiddleware

func CachingMiddleware(duration time.Duration, next http.Handler) http.Handler

func ContentNegotiationMiddleware

func ContentNegotiationMiddleware(next http.Handler) http.Handler

func LoggingMiddleware

func LoggingMiddleware(next http.Handler) http.Handler

func Param added in v0.1.6

func Param(r *http.Request, name string) string

Param function to extract parameters from the request context

func RateLimitMiddleware

func RateLimitMiddleware(next http.Handler) http.Handler

func RegisterParamType added in v0.1.6

func RegisterParamType(name, pattern string)

RegisterParamType allows the registration of custom parameter types with specific regex patterns

func RequestIDMiddleware

func RequestIDMiddleware(next http.Handler) http.Handler

func Respond

func Respond(w http.ResponseWriter, r *http.Request, status int, data interface{})

Respond handles content negotiation and responds in the appropriate format

func SetCSRFToken

func SetCSRFToken(w http.ResponseWriter)

Function to generate and set CSRF token cookie

func UploadFile

func UploadFile(r *http.Request, formKey, uploadDir string) (string, error)

func ValidateStruct

func ValidateStruct(s interface{}) error

Types

type CORSOptions

type CORSOptions struct {
	AllowedOrigins   []string
	AllowedMethods   []string
	AllowedHeaders   []string
	AllowCredentials bool
	ExposeHeaders    []string
}

type Middleware

type Middleware func(http.Handler) http.Handler

func CORS

func CORS(opts CORSOptions) Middleware

type MiddlewareChain

type MiddlewareChain []Middleware

type Route

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

type RouteGroup

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

func (*RouteGroup) Handle

func (g *RouteGroup) Handle(method, path string, handler http.HandlerFunc, middleware ...Middleware)

type Router

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

func NewRouter

func NewRouter() *Router

NewRouter creates a new Router instance

func (*Router) DELETE

func (r *Router) DELETE(path string, handler http.HandlerFunc)

func (*Router) GET

func (r *Router) GET(path string, handler http.HandlerFunc)

func (*Router) Group

func (r *Router) Group(version string) *RouteGroup

func (*Router) Handle

func (r *Router) Handle(method, path string, handler http.HandlerFunc, middleware ...Middleware)

Handle adds a new route to the router

func (*Router) POST

func (r *Router) POST(path string, handler http.HandlerFunc)

func (*Router) PUT

func (r *Router) PUT(path string, handler http.HandlerFunc)

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP makes the router implement the http.Handler interface Modified ServeHTTP function to apply middleware

func (*Router) Use

func (r *Router) Use(middleware ...Middleware)

Use adds new middleware to the router

Jump to

Keyboard shortcuts

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