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 RouteMockPoint(pointName string) func(next http.Handler) http.Handler
- func RouteMockReset()
- func SetForm(dataStore middleware.ContextDataStore, obj any)
- type Combo
- type Route
- func (r *Route) Any(pattern string, h ...any)
- func (r *Route) Combo(pattern string, h ...any) *Combo
- func (r *Route) Delete(pattern string, h ...any)
- func (r *Route) Get(pattern string, h ...any)
- func (r *Route) GetOptions(pattern string, h ...any)
- func (r *Route) Group(pattern string, fn func(), middlewares ...any)
- func (r *Route) Head(pattern string, h ...any)
- func (r *Route) Methods(method, pattern string, h ...any)
- func (r *Route) Mount(pattern string, subR *Route)
- func (r *Route) NotFound(h http.HandlerFunc)
- func (r *Route) Patch(pattern string, h ...any)
- func (r *Route) Post(pattern string, h ...any)
- func (r *Route) PostOptions(pattern string, h ...any)
- func (r *Route) Put(pattern string, h ...any)
- func (r *Route) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Route) 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 ¶ 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 RouteMockPoint ¶ added in v1.21.0
RouteMockPoint registers a mock point as a middleware for testing, example:
r.Use(web.RouteMockPoint("my-mock-point-1")) r.Get("/foo", middleware2, web.RouteMockPoint("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 RouteMockReset ¶ added in v1.21.0
func RouteMockReset()
RouteMockReset resets all mock points (no mock anymore)
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 Route ¶
type Route struct { R chi.Router // contains filtered or unexported fields }
Route defines a route based on chi's router
func (*Route) GetOptions ¶ added in v1.15.0
GetOptions delegate get and options method
func (*Route) NotFound ¶
func (r *Route) NotFound(h http.HandlerFunc)
NotFound defines a handler to respond whenever a route could not be found.
func (*Route) PostOptions ¶ added in v1.15.0
PostOptions delegate post and options method