Documentation ¶
Index ¶
- Variables
- func AddCheck(ctx *Context, check Check)
- func DELETE[T any](c *Context, handler func() (T, error), inputs ...any)
- func Float(c RouterOrContext, hn func(*Context, float64))
- func GET[T any](c *Context, handler func() (T, error), inputs ...any)
- func Int(c RouterOrContext, hn func(*Context, int))
- func IsBadRequest(err error) bool
- func OPTIONS[T any](c *Context, handler func() (T, error), inputs ...any)
- func PATCH[T any](c *Context, handler func() (T, error), inputs ...any)
- func POST[T any](c *Context, handler func() (T, error), inputs ...any)
- func PUT[T any](c *Context, handler func() (T, error), inputs ...any)
- func Remainder(c RouterOrContext, hn func(*Context, string))
- func Static(c RouterOrContext, text string, hn func(*Context))
- func String(c RouterOrContext, hn func(*Context, string))
- func Uint(c RouterOrContext, hn func(*Context, uint64))
- func WebSocket(c *Context, upgrader *websocket.Upgrader, handler func(*websocket.Conn) error)
- type BadRequest
- type CSRFValidator
- type Check
- type Context
- func (c *Context) Cookies() []*http.Cookie
- func (c *Context) GetAuthenticityToken() string
- func (c *Context) RemoteIP() net.IP
- func (c *Context) RequestHeaders() http.Header
- func (c *Context) ResponseHeaders() http.Header
- func (c *Context) SetCookie(cookie *http.Cookie)
- func (c *Context) URL() *url.URL
- type ErrorHandler
- type Redirect
- type Router
- type RouterOrContext
- type UserFacingError
Constants ¶
This section is empty.
Variables ¶
var RouteNotFound = errors.New("route not found")
RouteNotFound is used to define the error returned when a route is not found.
Functions ¶
func DELETE ¶ added in v0.1.2
DELETE is used to define a DELETE request in the current route context.
func Float ¶
func Float(c RouterOrContext, hn func(*Context, float64))
Float is used to match a floating point number.
func Int ¶
func Int(c RouterOrContext, hn func(*Context, int))
Int is used to match a signed integer.
func IsBadRequest ¶
IsBadRequest returns true if the error is a bad request error.
func OPTIONS ¶ added in v0.1.2
OPTIONS is used to define a OPTIONS request in the current route context.
func Remainder ¶ added in v0.4.0
func Remainder(c RouterOrContext, hn func(*Context, string))
Remainder is used to match the remainder of the path when there is more than 1 char after it. Returns the raw result.
func Static ¶
func Static(c RouterOrContext, text string, hn func(*Context))
Static is used to match based on the text content specified.
func String ¶
func String(c RouterOrContext, hn func(*Context, string))
String is used to match a string.
func Uint ¶
func Uint(c RouterOrContext, hn func(*Context, uint64))
Uint is used to match an unsigned integer.
Types ¶
type BadRequest ¶
type BadRequest struct {
Err error
}
BadRequest is the error type thrown when a bad request is made. It wraps the origin error as to why.
type CSRFValidator ¶ added in v0.3.0
type CSRFValidator struct{}
CSRFValidator is a special input that checks the authenticity token.
type Check ¶
type Check func() error
Check is used to check if the current route passes a check. If error is not nil, execution will be aborted and the error will be returned to the user.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is used to define the HTTP context.
func (*Context) GetAuthenticityToken ¶ added in v0.3.0
GetAuthenticityToken returns the authenticity token for the user. If one is not present, it makes it.
func (*Context) RemoteIP ¶
RemoteIP returns the remote IP address. If the request is behind a known proxy IP, it will try to get the real IP. Supported proxies are currently Cloudflare and Fastly.
func (*Context) RequestHeaders ¶
RequestHeaders returns the request headers.
func (*Context) ResponseHeaders ¶
ResponseHeaders returns the response headers.
type ErrorHandler ¶
ErrorHandler is used to used to define the error handler. The any is the error result that should be returned to the user.
type Redirect ¶ added in v0.1.4
Redirect is a special type that when detected will lead to a redirect.
func (Redirect) Body ¶ added in v0.1.4
Body returns itself to implement UserFacingError. This allows you to throw a redirect as a error and have it magically handled.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router is used to define the base router.
func (*Router) DisableAutoProxy ¶
func (r *Router) DisableAutoProxy()
DisableAutoProxy is used to turn off transforming trusted proxy servers into the real IP.
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements the http.Handler interface.
func (*Router) SetErrorHandler ¶ added in v0.1.3
func (r *Router) SetErrorHandler(h ErrorHandler)
SetErrorHandler is used to set the error handler.
func (*Router) SetMaxBodySize ¶
SetMaxBodySize sets the maximum body size for the router. 0 means the default of 2MB.
type RouterOrContext ¶
type RouterOrContext interface {
// contains filtered or unexported methods
}
RouterOrContext is used to define a interface that can be used for either *Router or *Context.
type UserFacingError ¶
type UserFacingError interface { // Status returns the HTTP status code. Status() int // Body returns the body of the error. Body() any }
UserFacingError is used to define a user facing error.