Documentation
¶
Index ¶
- Constants
- func Bind[T any](_ T) http.HandlerFunc
- func GetForm(dataStore reqctx.RequestDataStore) any
- func RegisterResponseStatusProvider[T any](fn func(req *http.Request) types.ResponseStatusProvider)
- func RouteMock(pointName string, h any) func()
- func RouteMockReset()
- func RouterMockPoint(pointName string) func(next http.Handler) http.Handler
- func SetForm(dataStore reqctx.ContextDataProvider, obj any)
- type Combo
- type PreMiddlewareProvider
- type Router
- func (r *Router) AfterRouting(middlewares ...any)
- func (r *Router) Any(pattern string, h ...any)
- func (r *Router) BeforeRouting(middlewares ...any)
- func (r *Router) Combo(pattern string, h ...any) *Combo
- func (r *Router) Delete(pattern string, h ...any)
- func (r *Router) Get(pattern string, h ...any)
- func (r *Router) Group(pattern string, fn func(), middlewares ...any)
- func (r *Router) Head(pattern string, h ...any)
- func (r *Router) Methods(methods, pattern string, h ...any)
- func (r *Router) Mount(pattern string, subRouter *Router)
- func (r *Router) NotFound(h http.HandlerFunc)
- func (r *Router) Patch(pattern string, h ...any)
- func (r *Router) PathGroup(pattern string, fn func(g *RouterPathGroup), h ...any)
- func (r *Router) Post(pattern string, h ...any)
- func (r *Router) Put(pattern string, h ...any)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- type RouterPathGroup
- func (g *RouterPathGroup) MatchPath(methods, pattern string, h ...any)
- func (g *RouterPathGroup) MatchPattern(methods string, pattern *RouterPathGroupPattern, h ...any)
- func (g *RouterPathGroup) PatternRegexp(pattern string, h ...any) *RouterPathGroupPattern
- func (g *RouterPathGroup) ServeHTTP(resp http.ResponseWriter, req *http.Request)
- type RouterPathGroupPattern
Constants ¶
const MockAfterMiddlewares = "MockAfterMiddlewares"
MockAfterMiddlewares is a general mock point, it's between middlewares and the handler
Variables ¶
This section is empty.
Functions ¶
func GetForm ¶
func GetForm(dataStore reqctx.RequestDataStore) any
GetForm returns the validate form information
func RegisterResponseStatusProvider ¶ added in v1.21.0
func RegisterResponseStatusProvider[T any](fn func(req *http.Request) types.ResponseStatusProvider)
func RouteMock ¶ added in v1.21.0
RouteMock uses the registered mock point to mock the route execution, example:
defer web.RouteMockReset()
web.RouteMock(web.MockAfterMiddlewares, func(ctx *context.Context) {
ctx.WriteResponse(...)
}
Then the mock function will be executed as a middleware at the mock point. It only takes effect in testing mode (setting.IsInTesting == true).
func RouteMockReset ¶ added in v1.21.0
func RouteMockReset()
RouteMockReset resets all mock points (no mock anymore)
func RouterMockPoint ¶ added in v1.23.0
RouterMockPoint registers a mock point as a middleware for testing, example:
r.Use(web.RouterMockPoint("my-mock-point-1"))
r.Get("/foo", middleware2, web.RouterMockPoint("my-mock-point-2"), middleware2, handler)
Then use web.RouteMock to mock the route execution. It only takes effect in testing mode (setting.IsInTesting == true).
func SetForm ¶
func SetForm(dataStore reqctx.ContextDataProvider, obj any)
SetForm set the form object
Types ¶
type Combo ¶
type Combo struct {
// contains filtered or unexported fields
}
Combo represents a tiny group routes with same pattern
type PreMiddlewareProvider ¶ added in v1.26.0
PreMiddlewareProvider is a special middleware provider which will be executed before other middlewares on the same "routing" level (AfterRouting/Group/Methods/Any, but not BeforeRouting). A route can do something (e.g.: set middleware options) at the place where it is declared, and the code will be executed before other middlewares which are added before the declaration. Use cases: mark a route with some meta info, set some options for middlewares, etc.
type Router ¶ added in v1.23.0
type Router struct {
// contains filtered or unexported fields
}
Router defines a route based on chi's router
func (*Router) AfterRouting ¶ added in v1.26.0
AfterRouting adds middlewares which will be executed after the request path gets routed It can see the routed path and resolved path parameters
func (*Router) BeforeRouting ¶ added in v1.26.0
BeforeRouting adds middlewares which will be executed before the request path gets routed It should only be used for framework-level global middlewares when it needs to change request method & path.
func (*Router) Methods ¶ added in v1.23.0
Methods adds the same handlers for multiple http "methods" (separated by ","). If any method is invalid, the lower level router will panic.
func (*Router) NotFound ¶ added in v1.23.0
func (r *Router) NotFound(h http.HandlerFunc)
NotFound defines a handler to respond whenever a route could not be found.
func (*Router) PathGroup ¶ added in v1.24.0
func (r *Router) PathGroup(pattern string, fn func(g *RouterPathGroup), h ...any)
PathGroup creates a group of paths which could be matched by regexp. It is only designed to resolve some special cases which chi router can't handle. For most cases, it shouldn't be used because it needs to iterate all rules to find the matched one (inefficient).
type RouterPathGroup ¶ added in v1.24.0
type RouterPathGroup struct {
// contains filtered or unexported fields
}
func (*RouterPathGroup) MatchPath ¶ added in v1.24.0
func (g *RouterPathGroup) MatchPath(methods, pattern string, h ...any)
MatchPath matches the request method, and uses regexp to match the path. The pattern uses "<...>" to define path parameters, for example, "/<name>" (different from chi router) It is only designed to resolve some special cases that chi router can't handle. For most cases, it shouldn't be used because it needs to iterate all rules to find the matched one (inefficient).
func (*RouterPathGroup) MatchPattern ¶ added in v1.25.0
func (g *RouterPathGroup) MatchPattern(methods string, pattern *RouterPathGroupPattern, h ...any)
func (*RouterPathGroup) PatternRegexp ¶ added in v1.25.0
func (g *RouterPathGroup) PatternRegexp(pattern string, h ...any) *RouterPathGroupPattern
func (*RouterPathGroup) ServeHTTP ¶ added in v1.24.0
func (g *RouterPathGroup) ServeHTTP(resp http.ResponseWriter, req *http.Request)
type RouterPathGroupPattern ¶ added in v1.25.0
type RouterPathGroupPattern struct {
// contains filtered or unexported fields
}