Documentation ¶
Index ¶
Constants ¶
View Source
const ( ContentTypeApplicationJSON = "application/json" ContentTypeTextPlain = "text/plain" ContentTypeFormURLEncoded = "application/x-www-form-urlencoded" ContentTypeMultipart = "multipart/form-data" ContentTypeApplicationJSONUTF8 = "application/json; charset=utf-8" ContentTypeTextPlainUTF8 = "text/plain; charset=utf-8" )
Variables ¶
View Source
var Module = fx.Module( "winterfx_core_routefx", fx.Provide( New, flagfx.AsDecoderFunc(DecodeParams), ), )
Functions ¶
func AsRouteProvider ¶
func AsRouteProvider[T any](fn func(v T) (pattern string, h HandlerFunc)) any
Types ¶
type Context ¶
type Context interface { // Context extend the [context.Context] interface by proxying to [http.Request.Context] context.Context // Inject inject underlying [context.Context] Inject(fn func(ctx context.Context) context.Context) // Req returns the underlying *http.Request Req() *http.Request // Header returns the headers of underlying [http.ResponseWriter] Header() http.Header // Bind unmarshal the request data into any struct with json tags // // HTTP header is prefixed with "header_" // // HTTP query is prefixed with "query_" // // both JSON and Form are supported Bind(data interface{}) // Files returns the multipart file headers Files() map[string][]*multipart.FileHeader // Code set the response code, can be called multiple times Code(code int) // Body set the response body with content type, can be called multiple times Body(contentType string, buf []byte) // Text set the response body to plain text Text(s string) // JSON set the response body to json JSON(data interface{}) // Perform actually perform the response // it is suggested to use in defer, recover() is included to recover from any panics Perform() }
Context context of an incoming request and corresponding response writer
func NewContext ¶
func NewContext(rw http.ResponseWriter, req *http.Request) Context
type HandlerFunc ¶
type HandlerFunc func(c Context)
HandlerFunc handler func with Context as argument
type Params ¶
func DecodeParams ¶
type Route ¶
type Route struct { Pattern string HandlerFunc }
Route a route with pattern and handler
func (Route) ToHTTPHandler ¶
func (r Route) ToHTTPHandler(opts RouteOptions) http.Handler
type RouteOptions ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.