Documentation
¶
Index ¶
- func DefaultNotFoundHandler(w http.ResponseWriter, req *http.Request, _ Params)
- func DefaultPanicHandler(w http.ResponseWriter, req *http.Request, v any)
- type Handler
- type OnRequestDone
- type Options
- type PanicHandler
- type Param
- type Params
- type Route
- type Router
- func (r *Router) AddRoute(group, method, route string, h Handler) *Route
- func (r *Router) AddRouteWithDesc(group, method, route string, h Handler, desc string) *Route
- func (r *Router) DisableRoute(method, path string, disabled bool) bool
- func (r *Router) GetRoutes() [][3]string
- func (r *Router) Match(method, path string) (rn *Route, params Params)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) Swagger() *Swagger
- type Swagger
- type SwaggerDefinition
- type SwaggerDefinitionField
- type SwaggerDesc
- type SwaggerInfo
- type SwaggerParam
- type SwaggerPath
- type SwaggerRequestBody
- type SwaggerRequestBodyContent
- type SwaggerRoute
- func (sr *SwaggerRoute) AsPublic() *SwaggerRoute
- func (sr *SwaggerRoute) WithBody(contentType string, example any) *SwaggerRoute
- func (sr *SwaggerRoute) WithDescription(v string) *SwaggerRoute
- func (sr *SwaggerRoute) WithExample(name string, ex *SwaggerDesc) *SwaggerRoute
- func (sr *SwaggerRoute) WithOperationID(v string) *SwaggerRoute
- func (sr *SwaggerRoute) WithParam(name, desc, in, typ string, required bool, schema *SwaggerDefinition) *SwaggerRoute
- func (sr *SwaggerRoute) WithParams(params []*SwaggerParam) *SwaggerRoute
- func (sr *SwaggerRoute) WithResponse(name string, ex *SwaggerDesc) *SwaggerRoute
- func (sr *SwaggerRoute) WithSummary(v string) *SwaggerRoute
- func (sr *SwaggerRoute) WithTags(v ...string) *SwaggerRoute
- type SwaggerServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultNotFoundHandler ¶
func DefaultNotFoundHandler(w http.ResponseWriter, req *http.Request, _ Params)
DefaultNotFoundHandler is the default panic handler
func DefaultPanicHandler ¶
func DefaultPanicHandler(w http.ResponseWriter, req *http.Request, v any)
DefaultPanicHandler is the default panic handler
Types ¶
type Handler ¶
type Handler = func(w http.ResponseWriter, req *http.Request, p Params)
Handler is what handler looks like, duh? *note* `p` is NOT safe to be used outside the handler, call p.Copy() if you need to use it.
type OnRequestDone ¶
type Options ¶
type Options struct { OnRequestDone APIInfo *SwaggerInfo NoAutoCleanURL bool // don't automatically clean URLs, not recommended NoDefaultPanicHandler bool // don't use the default panic handler NoPanicOnInvalidAddRoute bool // don't panic on invalid routes, return an error instead CatchPanics bool // don't catch panics NoAutoHeadToGet bool // disable automatically handling HEAD requests ProfileLabels bool AutoGenerateSwagger bool }
Options passed to the router
type PanicHandler ¶
type PanicHandler = func(w http.ResponseWriter, req *http.Request, v any)
PanicHandler is a special handler that gets called if a panic happens
type Params ¶
type Params []Param
Params handles the named params in your url, it is *NOT* safe to be used outside of your handler.
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
func RouteFromRequest ¶ added in v1.1.0
type Router ¶
type Router struct { NotFoundHandler Handler MethodNotAllowedHandler Handler PanicHandler PanicHandler // contains filtered or unexported fields }
Router is an efficient routing library
func (*Router) AddRoute ¶
AddRoute adds a Handler to the specific method and route. Calling AddRoute after starting the http server is racy and not supported.
func (*Router) AddRouteWithDesc ¶
AddRoute adds a Handler to the specific method and route. Calling AddRoute after starting the http server is racy and not supported.
func (*Router) DisableRoute ¶ added in v1.1.0
func (*Router) Match ¶
Match matches a method and path to a handler. if METHOD == HEAD and there isn't a specific handler for it, it returns the GET handler for the path.
type Swagger ¶
type Swagger struct { OpenAPI string `json:"openapi,omitempty" yaml:"openapi,omitempty"` Server []SwaggerServer `json:"server,omitempty" yaml:"server,omitempty"` Info *SwaggerInfo `json:"info,omitempty" yaml:"info,omitempty"` Paths SwaggerPath `json:"paths,omitempty" yaml:"paths,omitempty"` Definitions map[string]*SwaggerDefinition `json:"definitions,omitempty" yaml:"definitions,omitempty"` }
type SwaggerDefinition ¶ added in v1.1.0
type SwaggerDefinitionField ¶ added in v1.1.0
type SwaggerDesc ¶
type SwaggerDesc struct { Summary string `json:"summary,omitempty" yaml:"summary,omitempty"` Description string `json:"description,omitempty" yaml:"description,omitempty"` Value any `json:"value,omitempty" yaml:"value,omitempty"` ExternalValue string `json:"externalValue,omitempty" yaml:"externalValue,omitempty"` }
type SwaggerInfo ¶
type SwaggerParam ¶
type SwaggerParam struct { Name string `json:"name,omitempty" yaml:"name,omitempty"` In string `json:"in,omitempty" yaml:"in,omitempty"` Description string `json:"description,omitempty" yaml:"description,omitempty"` Type string `json:"-" yaml:"-"` Schema *SwaggerDefinition `json:"schema,omitempty" yaml:"schema,omitempty"` Required bool `json:"required,omitempty" yaml:"required,omitempty"` Deprecated bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"` AllowEmptyValue bool `json:"allowEmptyValue,omitempty" yaml:"allowEmptyValue,omitempty"` }
type SwaggerPath ¶
type SwaggerPath = map[string]map[string]*SwaggerRoute
....................path.......method
type SwaggerRequestBody ¶ added in v1.1.0
type SwaggerRequestBody struct { Description string `json:"description,omitempty" yaml:"description,omitempty"` Content map[string]*SwaggerRequestBodyContent `json:"content,omitempty" yaml:"value,omitempty"` Required bool `json:"required,omitempty" yaml:"required,omitempty"` }
type SwaggerRequestBodyContent ¶ added in v1.1.0
type SwaggerRequestBodyContent struct { Example string `json:"example,omitempty" yaml:"example,omitempty"` Examples map[string]*SwaggerDesc `json:"examples,omitempty" yaml:"examples,omitempty"` }
type SwaggerRoute ¶
type SwaggerRoute struct { OperationID string `json:"operationID,omitempty" yaml:"operationID,omitempty"` Summary string `json:"summary,omitempty" yaml:"summary,omitempty"` Description string `json:"description,omitempty" yaml:"description,omitempty"` Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"` Parameters []*SwaggerParam `json:"parameters,omitempty" yaml:"parameters,omitempty"` RequestBody *SwaggerRequestBody `json:"requestBody,omitempty" yaml:"requestBody,omitempty"` Responses map[string]*SwaggerDesc `json:"responses,omitempty" yaml:"responses,omitempty"` Examples map[string]*SwaggerDesc `json:"examples,omitempty" yaml:"examples,omitempty"` Public bool `json:"public,omitempty" yaml:"public,omitempty"` }
func (*SwaggerRoute) AsPublic ¶ added in v1.1.0
func (sr *SwaggerRoute) AsPublic() *SwaggerRoute
AsPublic designates this route as public documentation.
func (*SwaggerRoute) WithBody ¶ added in v1.1.0
func (sr *SwaggerRoute) WithBody(contentType string, example any) *SwaggerRoute
func (*SwaggerRoute) WithDescription ¶
func (sr *SwaggerRoute) WithDescription(v string) *SwaggerRoute
func (*SwaggerRoute) WithExample ¶
func (sr *SwaggerRoute) WithExample(name string, ex *SwaggerDesc) *SwaggerRoute
func (*SwaggerRoute) WithOperationID ¶
func (sr *SwaggerRoute) WithOperationID(v string) *SwaggerRoute
func (*SwaggerRoute) WithParam ¶
func (sr *SwaggerRoute) WithParam(name, desc, in, typ string, required bool, schema *SwaggerDefinition) *SwaggerRoute
func (*SwaggerRoute) WithParams ¶
func (sr *SwaggerRoute) WithParams(params []*SwaggerParam) *SwaggerRoute
func (*SwaggerRoute) WithResponse ¶
func (sr *SwaggerRoute) WithResponse(name string, ex *SwaggerDesc) *SwaggerRoute
func (*SwaggerRoute) WithSummary ¶
func (sr *SwaggerRoute) WithSummary(v string) *SwaggerRoute
func (*SwaggerRoute) WithTags ¶
func (sr *SwaggerRoute) WithTags(v ...string) *SwaggerRoute