Documentation ¶
Index ¶
- Constants
- func Bind[T any](_ T) http.HandlerFunc
- func GetForm(dataStore middleware.ContextDataStore) any
- func RegisterResponseStatusProvider[T any](fn func(req *http.Request) types.ResponseStatusProvider)
- func RouteMock(pointName string, h any)
- func RouteMockReset()
- func RouterMockPoint(pointName string) func(next http.Handler) http.Handler
- func SetForm(dataStore middleware.ContextDataStore, obj any)
- type Combo
- type Router
- func (r *Router) Any(pattern string, h ...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) Post(pattern string, h ...any)
- func (r *Router) Put(pattern string, h ...any)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) Use(middlewares ...any)
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 middleware.ContextDataStore) any
GetForm returns the validate form information
func RegisterResponseStatusProvider ¶
func RegisterResponseStatusProvider[T any](fn func(req *http.Request) types.ResponseStatusProvider)
func RouteMock ¶
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 RouterMockPoint ¶
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 middleware.ContextDataStore, 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 Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router defines a route based on chi's router
func (*Router) Methods ¶
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 ¶
func (r *Router) NotFound(h http.HandlerFunc)
NotFound defines a handler to respond whenever a route could not be found.