Documentation ¶
Index ¶
- Variables
- func Validate(givenSchema *api.Schema, rawValue any, v *Validator)
- func ValidateInjectable(inj Injectable, scope *deps.Scope) error
- type Accepted
- type BadRequest
- func (err BadRequest[V]) APIName() string
- func (err BadRequest[V]) APISchemaType() any
- func (err BadRequest[V]) Error() string
- func (err BadRequest[V]) HTTPStatus() int
- func (err BadRequest[V]) HTTPStatuses() []int
- func (err BadRequest[V]) MarshalJSON() ([]byte, error)
- func (err *BadRequest[V]) UnmarshalJSON(data []byte) error
- type Body
- type CanSend
- type CanValidateFull
- type CanValidatePost
- type Conflict
- func (err Conflict[V]) APIName() string
- func (err Conflict[V]) APISchemaType() any
- func (err Conflict[V]) Error() string
- func (err Conflict[V]) HTTPStatus() int
- func (err Conflict[V]) HTTPStatuses() []int
- func (err Conflict[V]) MarshalJSON() ([]byte, error)
- func (err *Conflict[V]) UnmarshalJSON(data []byte) error
- type Created
- type ErrorHandler
- type Forbidden
- func (err Forbidden[V]) APIName() string
- func (err Forbidden[V]) APISchemaType() any
- func (err Forbidden[V]) Error() string
- func (err Forbidden[V]) HTTPStatus() int
- func (err Forbidden[V]) HTTPStatuses() []int
- func (err Forbidden[V]) MarshalJSON() ([]byte, error)
- func (err *Forbidden[V]) UnmarshalJSON(data []byte) error
- type HandledError
- type HasContentType
- type HasStatus
- type Header
- type Injectable
- type InternalErrorHandler
- type InternalServerError
- func (err InternalServerError[V]) APIName() string
- func (err InternalServerError[V]) APISchemaType() any
- func (err InternalServerError[V]) Error() string
- func (err InternalServerError[V]) HTTPStatus() int
- func (err InternalServerError[V]) HTTPStatuses() []int
- func (err InternalServerError[V]) MarshalJSON() ([]byte, error)
- func (err *InternalServerError[V]) UnmarshalJSON(data []byte) error
- type MiddlewareNext
- type Moved
- type None
- type NotFound
- func (err NotFound[V]) APIName() string
- func (err NotFound[V]) APISchemaType() any
- func (err NotFound[V]) Error() string
- func (err NotFound[V]) HTTPStatus() int
- func (err NotFound[V]) HTTPStatuses() []int
- func (err NotFound[V]) MarshalJSON() ([]byte, error)
- func (err *NotFound[V]) UnmarshalJSON(data []byte) error
- type NotImplemented
- func (err NotImplemented[V]) APIName() string
- func (err NotImplemented[V]) APISchemaType() any
- func (err NotImplemented[V]) Error() string
- func (err NotImplemented[V]) HTTPStatus() int
- func (err NotImplemented[V]) HTTPStatuses() []int
- func (err NotImplemented[V]) MarshalJSON() ([]byte, error)
- func (err *NotImplemented[V]) UnmarshalJSON(data []byte) error
- type OK
- type Path
- type PaymentRequired
- func (err PaymentRequired[V]) APIName() string
- func (err PaymentRequired[V]) APISchemaType() any
- func (err PaymentRequired[V]) Error() string
- func (err PaymentRequired[V]) HTTPStatus() int
- func (err PaymentRequired[V]) HTTPStatuses() []int
- func (err PaymentRequired[V]) MarshalJSON() ([]byte, error)
- func (err *PaymentRequired[V]) UnmarshalJSON(data []byte) error
- type Query
- type Request
- type RequestTypes
- type Result
- type Router
- type RouterOperation
- type ServiceUnavailable
- func (err ServiceUnavailable[V]) APIName() string
- func (err ServiceUnavailable[V]) APISchemaType() any
- func (err ServiceUnavailable[V]) Error() string
- func (err ServiceUnavailable[V]) HTTPStatus() int
- func (err ServiceUnavailable[V]) HTTPStatuses() []int
- func (err ServiceUnavailable[V]) MarshalJSON() ([]byte, error)
- func (err *ServiceUnavailable[V]) UnmarshalJSON(data []byte) error
- type Site
- func (site *Site) AddResponse(code string, response api.Response)
- func (site *Site) AddResponses(responses api.Responses)
- func (site *Site) AddTags(tags []string)
- func (site *Site) BuildDocument() *api.Document
- func (site *Site) BuildJSON() []byte
- func (site Site) Chi() chi.Router
- func (site *Site) Connect(pattern string, fn any)
- func (site *Site) CreatePath(pattern string) *api.Path
- func (site *Site) DefineBody(bodies ...any)
- func (site *Site) DefineHeader(bodies ...any)
- func (site *Site) DefinePath(paths ...any)
- func (site *Site) DefineQuery(bodies ...any)
- func (site *Site) Delete(pattern string, fn any, operations ...api.Operation) RouterOperation
- func (site *Site) EnableValidation(enabled bool)
- func (site *Site) Get(pattern string, fn any, operations ...api.Operation) RouterOperation
- func (site *Site) GetOperations() *api.Operation
- func (site *Site) GetPath(pattern string) *api.Path
- func (site *Site) GetScope(response http.ResponseWriter, request *http.Request) (requestScope *deps.Scope, freeScope bool)
- func (site *Site) Group(fn func(r Router)) Router
- func (site *Site) HandleError(err error, response http.ResponseWriter, request *http.Request, ...) error
- func (site *Site) HandleFunc(pattern string, fn any, operations ...api.Operation) *api.Path
- func (site *Site) Head(pattern string, fn any, operations ...api.Operation) RouterOperation
- func (site *Site) Listen(addr string)
- func (site *Site) MethodFunc(method string, pattern string, fn any, operations ...api.Operation) RouterOperation
- func (site *Site) MethodNotAllowed(fn any)
- func (site *Site) NotFound(fn any)
- func (site *Site) Options(pattern string, fn any, operations ...api.Operation) RouterOperation
- func (site *Site) Patch(pattern string, fn any, operations ...api.Operation) RouterOperation
- func (site *Site) Post(pattern string, fn any, operations ...api.Operation) RouterOperation
- func (site *Site) PrintPaths()
- func (site *Site) Put(pattern string, fn any, operations ...api.Operation) RouterOperation
- func (site *Site) Route(pattern string, fn func(r Router)) Router
- func (site *Site) Run()
- func (site *Site) Send(response any, w http.ResponseWriter) error
- func (site *Site) SendAny(response []byte, w http.ResponseWriter, status int, ...)
- func (site *Site) ServeOpenJSON(pattern string)
- func (site *Site) ServeRedoc(pattern string)
- func (site *Site) ServeSwaggerUI(pattern string, options map[string]any)
- func (site *Site) SetErrorHandler(handler ErrorHandler)
- func (site *Site) SetInternalErrorHandler(handle InternalErrorHandler)
- func (site *Site) SetOperations(op api.Operation)
- func (site *Site) SetResponses(responses api.Responses)
- func (site *Site) SetTags(tags []string)
- func (site *Site) SetValidationOptions(valueOrType any, options ValidationOptions)
- func (site *Site) Trace(pattern string, fn any, operations ...api.Operation) RouterOperation
- func (site Site) URL() string
- func (site *Site) UpdateOperations(op api.Operation)
- func (site *Site) UpdatePath(pattern string, path api.Path)
- func (site *Site) Use(fns ...any)
- func (site Site) ValidationOptions(typ reflect.Type) ValidationOptions
- func (site *Site) With(fns ...any) Router
- type SiteOperation
- type TooManyRequests
- func (err TooManyRequests[V]) APIName() string
- func (err TooManyRequests[V]) APISchemaType() any
- func (err TooManyRequests[V]) Error() string
- func (err TooManyRequests[V]) HTTPStatus() int
- func (err TooManyRequests[V]) HTTPStatuses() []int
- func (err TooManyRequests[V]) MarshalJSON() ([]byte, error)
- func (err *TooManyRequests[V]) UnmarshalJSON(data []byte) error
- type Unauthorized
- func (err Unauthorized[V]) APIName() string
- func (err Unauthorized[V]) APISchemaType() any
- func (err Unauthorized[V]) Error() string
- func (err Unauthorized[V]) HTTPStatus() int
- func (err Unauthorized[V]) HTTPStatuses() []int
- func (err Unauthorized[V]) MarshalJSON() ([]byte, error)
- func (err *Unauthorized[V]) UnmarshalJSON(data []byte) error
- type Validation
- type ValidationOptions
- type ValidationProvider
- type ValidationRule
- type Validator
- func (v *Validator) Add(msg Validation)
- func (v *Validator) Attach(detached Validator)
- func (v Validator) Detach() Validator
- func (v Validator) Error() string
- func (v Validator) HTTPStatus() int
- func (v Validator) HTTPStatuses() []int
- func (v Validator) HasFailures() bool
- func (v Validator) IsValid() bool
- func (v Validator) Next(path string) *Validator
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupportedType = errors.New("unsupported type")
var ScopeKey = scopeKey{"RezScope"}
Functions ¶
func ValidateInjectable ¶
func ValidateInjectable(inj Injectable, scope *deps.Scope) error
Validates the injectable by pulling the validator and operation off of the scope and calling APIValidate. If there are any validation errors the validator (which implements error) is returned.
Types ¶
type Accepted ¶
type Accepted[V any] struct { Result V }
A 202 response.
func NewAccepted ¶
func (Accepted[V]) APISchemaType ¶ added in v0.3.4
func (Accepted[V]) HTTPStatus ¶
func (Accepted[V]) HTTPStatuses ¶
func (Accepted[V]) MarshalJSON ¶
func (*Accepted[V]) UnmarshalJSON ¶
type BadRequest ¶
type BadRequest[V any] struct { Result V }
A 400 response.
func NewBadRequest ¶
func NewBadRequest[V any](result V) *BadRequest[V]
func (BadRequest[V]) APIName ¶ added in v0.3.4
func (err BadRequest[V]) APIName() string
func (BadRequest[V]) APISchemaType ¶ added in v0.3.4
func (err BadRequest[V]) APISchemaType() any
func (BadRequest[V]) Error ¶
func (err BadRequest[V]) Error() string
func (BadRequest[V]) HTTPStatus ¶
func (err BadRequest[V]) HTTPStatus() int
func (BadRequest[V]) HTTPStatuses ¶
func (err BadRequest[V]) HTTPStatuses() []int
func (BadRequest[V]) MarshalJSON ¶
func (err BadRequest[V]) MarshalJSON() ([]byte, error)
func (*BadRequest[V]) UnmarshalJSON ¶
func (err *BadRequest[V]) UnmarshalJSON(data []byte) error
type Body ¶
type Body[B any] struct { Value B }
A function parameter that is injected with the request body.
func (Body[B]) APIRequestTypes ¶
func (b Body[B]) APIRequestTypes() RequestTypes
type CanSend ¶
type CanSend interface {
HTTPSend(w http.ResponseWriter) error
}
A response which has custom sending logic.
type CanValidateFull ¶
type CanValidateFull interface {
FullValidate(v *Validator)
}
If a type implements this interface then it handles all validation for the type.
type CanValidatePost ¶
type CanValidatePost interface {
PostValidate(v *Validator)
}
If a type implements this interface then it handles validation after the normal validation process has occurred.
type Conflict ¶
type Conflict[V any] struct { Result V }
A 409 response.
func NewConflict ¶
func (Conflict[V]) APISchemaType ¶ added in v0.3.4
func (Conflict[V]) HTTPStatus ¶
func (Conflict[V]) HTTPStatuses ¶
func (Conflict[V]) MarshalJSON ¶
func (*Conflict[V]) UnmarshalJSON ¶
type Created ¶
type Created[V any] struct { Result V }
A 201 response.
func NewCreated ¶
func (Created[V]) APISchemaType ¶ added in v0.3.4
func (Created[V]) HTTPStatus ¶
func (Created[V]) HTTPStatuses ¶
func (Created[V]) MarshalJSON ¶
func (*Created[V]) UnmarshalJSON ¶
type ErrorHandler ¶
type ErrorHandler = func(err error, response http.ResponseWriter, request *http.Request, scope *deps.Scope) (bool, error)
A function which handles the error and returns true or returns false for the error to be handled by default behavior.
type Forbidden ¶
type Forbidden[V any] struct { Result V }
A 403 response.
func NewForbidden ¶
func (Forbidden[V]) APISchemaType ¶ added in v0.3.4
func (Forbidden[V]) HTTPStatus ¶
func (Forbidden[V]) HTTPStatuses ¶
func (Forbidden[V]) MarshalJSON ¶
func (*Forbidden[V]) UnmarshalJSON ¶
type HandledError ¶
type HandledError interface { error // Handle the error Handle(response http.ResponseWriter, request *http.Request, scope *deps.Scope) error }
An error type which has custom error handling.
type HasContentType ¶
type HasContentType interface {
HTTPContentType() string
}
A response which has a custom content type.
type HasStatus ¶
type HasStatus interface { // The status of this particular response HTTPStatus() int // All possible statuses for this response type HTTPStatuses() []int }
A response type that has a known status but could return more than one status. HTTPStatus is used when returning a response and HTTPStatuses is used for documentation.
type Header ¶
type Header[H any] struct { Value H }
A function parameter that is injected with the request headers.
func (Header[H]) APIRequestTypes ¶
func (h Header[H]) APIRequestTypes() RequestTypes
type Injectable ¶
type Injectable interface { deps.Dynamic // Return the types for any request types in this injectable. APIRequestTypes() RequestTypes // Do validation for this type. APIValidate(op *api.Operation, v *Validator) }
A type which has one or more injectable request types. This is how the dependency injected functions are inspected for types which are added to the Open API document.
type InternalErrorHandler ¶
type InternalErrorHandler = func(err error)
A function which handles an error that couldn't be sent to the client.
type InternalServerError ¶
type InternalServerError[V any] struct { Result V }
A 500 response.
func NewInternalServerError ¶
func NewInternalServerError[V any](result V) *InternalServerError[V]
func (InternalServerError[V]) APIName ¶ added in v0.3.4
func (err InternalServerError[V]) APIName() string
func (InternalServerError[V]) APISchemaType ¶ added in v0.3.4
func (err InternalServerError[V]) APISchemaType() any
func (InternalServerError[V]) Error ¶
func (err InternalServerError[V]) Error() string
func (InternalServerError[V]) HTTPStatus ¶
func (err InternalServerError[V]) HTTPStatus() int
func (InternalServerError[V]) HTTPStatuses ¶
func (err InternalServerError[V]) HTTPStatuses() []int
func (InternalServerError[V]) MarshalJSON ¶
func (err InternalServerError[V]) MarshalJSON() ([]byte, error)
func (*InternalServerError[V]) UnmarshalJSON ¶
func (err *InternalServerError[V]) UnmarshalJSON(data []byte) error
type MiddlewareNext ¶
type MiddlewareNext func()
The function to forward middleware onto the next handler. To change the request or response refer to them in the injectable function arguments as a pointer and change the value.
func NewMiddlewareNext ¶
func NewMiddlewareNext(h http.Handler, scope *deps.Scope) MiddlewareNext
Creates a new MiddlewareNext given a handler and scope.
type Moved ¶ added in v0.3.4
type Moved[V any] struct { Result V }
A 301 response.
func (Moved[V]) APISchemaType ¶ added in v0.3.4
func (Moved[V]) HTTPStatus ¶ added in v0.3.4
func (Moved[V]) HTTPStatuses ¶ added in v0.3.4
func (Moved[V]) MarshalJSON ¶ added in v0.3.4
func (*Moved[V]) UnmarshalJSON ¶ added in v0.3.4
type NotFound ¶
type NotFound[V any] struct { Result V }
A 404 response.
func NewNotFound ¶
func (NotFound[V]) APISchemaType ¶ added in v0.3.4
func (NotFound[V]) HTTPStatus ¶
func (NotFound[V]) HTTPStatuses ¶
func (NotFound[V]) MarshalJSON ¶
func (*NotFound[V]) UnmarshalJSON ¶
type NotImplemented ¶
type NotImplemented[V any] struct { Result V }
A 501 response.
func NewNotImplemented ¶
func NewNotImplemented[V any](result V) *NotImplemented[V]
func (NotImplemented[V]) APIName ¶ added in v0.3.4
func (err NotImplemented[V]) APIName() string
func (NotImplemented[V]) APISchemaType ¶ added in v0.3.4
func (err NotImplemented[V]) APISchemaType() any
func (NotImplemented[V]) Error ¶
func (err NotImplemented[V]) Error() string
func (NotImplemented[V]) HTTPStatus ¶
func (err NotImplemented[V]) HTTPStatus() int
func (NotImplemented[V]) HTTPStatuses ¶
func (err NotImplemented[V]) HTTPStatuses() []int
func (NotImplemented[V]) MarshalJSON ¶
func (err NotImplemented[V]) MarshalJSON() ([]byte, error)
func (*NotImplemented[V]) UnmarshalJSON ¶
func (err *NotImplemented[V]) UnmarshalJSON(data []byte) error
type OK ¶
type OK[V any] struct { Result V }
A 200 response.
func (OK[V]) APISchemaType ¶ added in v0.3.4
func (OK[V]) HTTPStatus ¶
func (OK[V]) HTTPStatuses ¶
func (OK[V]) MarshalJSON ¶
func (*OK[V]) UnmarshalJSON ¶
type Path ¶
type Path[P any] struct { Value P }
A function parameter that is injected with path parameters.
func (Path[P]) APIRequestTypes ¶
func (p Path[P]) APIRequestTypes() RequestTypes
type PaymentRequired ¶ added in v0.3.4
type PaymentRequired[V any] struct { Result V }
A 402 response.
func NewPaymentRequired ¶ added in v0.3.4
func NewPaymentRequired[V any](result V) *PaymentRequired[V]
func (PaymentRequired[V]) APIName ¶ added in v0.3.4
func (err PaymentRequired[V]) APIName() string
func (PaymentRequired[V]) APISchemaType ¶ added in v0.3.4
func (err PaymentRequired[V]) APISchemaType() any
func (PaymentRequired[V]) Error ¶ added in v0.3.4
func (err PaymentRequired[V]) Error() string
func (PaymentRequired[V]) HTTPStatus ¶ added in v0.3.4
func (err PaymentRequired[V]) HTTPStatus() int
func (PaymentRequired[V]) HTTPStatuses ¶ added in v0.3.4
func (err PaymentRequired[V]) HTTPStatuses() []int
func (PaymentRequired[V]) MarshalJSON ¶ added in v0.3.4
func (err PaymentRequired[V]) MarshalJSON() ([]byte, error)
func (*PaymentRequired[V]) UnmarshalJSON ¶ added in v0.3.4
func (err *PaymentRequired[V]) UnmarshalJSON(data []byte) error
type Query ¶
type Query[Q any] struct { Value Q }
A function parameter that is injected with query parameters.
func (Query[Q]) APIRequestTypes ¶
func (q Query[Q]) APIRequestTypes() RequestTypes
type Request ¶
A function parameter that is injected with the body, path, and query parameters.
func (Request[B, P, Q]) APIRequestTypes ¶
func (r Request[B, P, Q]) APIRequestTypes() RequestTypes
func (Request[B, P, Q]) APIValidate ¶
type RequestTypes ¶
type RequestTypes struct { Body reflect.Type Path reflect.Type Query reflect.Type Header reflect.Type }
A value that holds types, so the dependency injection system can pick up on the types that represent the parts of a request.
type Result ¶
A custom status response. The documentation will not be able to report on the status of this type, you need to use one of the provided types or define your own implementor of HasStatus.
func (Result[V]) APISchemaType ¶ added in v0.3.4
func (Result[V]) HTTPStatus ¶
func (Result[V]) HTTPStatuses ¶
func (Result[V]) MarshalJSON ¶
func (*Result[V]) UnmarshalJSON ¶
type Router ¶
type Router interface { ValidationProvider // The internal chi.Router Chi() chi.Router // The url of the router at this point. URL() string // Sets the error handler at this router and all sub routers created after this is set. SetErrorHandler(handler ErrorHandler) // Sets the handler for errors we received outside of responding to the client. SetInternalErrorHandler(handle InternalErrorHandler) // Handles the given error if its a HandledError, is handled by the error handler, or is handled with default behavior. HandleError(err error, response http.ResponseWriter, request *http.Request, scope *deps.Scope) error // Enables or disables validation for all routes in this router or sub routers created after this is set. // By default validation is not enabled. EnableValidation(enabled bool) // Sets the validation options for the type or value's type. SetValidationOptions(valueOrType any, options ValidationOptions) // Adds the types of the given values as injectable request bodies. This avoids // the necessity of rez.Body or rez.Request. If any of the values/types // have already been defined this will cause a panic. DefineBody(bodies ...any) // Adds the types of the given values as injectable parameters. This avoids // the necessity of rez.Param or rez.Request. If any of the values/types // have already been defined this will cause a panic. DefinePath(params ...any) // Adds the types of the given values as injectable query parameters. This avoids // the necessity of rez.Query or rez.Request. If any of the values/types // have already been defined this will cause a panic. DefineQuery(queries ...any) // Adds the types of the given values as injectable header values. This avoids // the necessity of rez.Header. If any of the values/types // have already been defined this will cause a panic. DefineHeader(headers ...any) // Gets the base operation which has all inherited tags and responses set at the current router. GetOperations() *api.Operation // Sets the base operation. All sub routes will inherit the properties on the base operation. SetOperations(op api.Operation) // Updates the base operation (merges in given properties into existing base operation). // All sub routes will inherit the properties on the base operation. UpdateOperations(op api.Operation) // Gets the path defined at the given pattern, if any GetPath(pattern string) *api.Path // Gets the path define at the given pattern, creating it if need be. CreatePath(pattern string) *api.Path // Merges the path definition into the path UpdatePath(pattern string, path api.Path) // Sets the tags for all child routes starting at this router. // This is similar to router.SetOperation(api.Operation{Tags: tags}). SetTags(tags []string) // Adds the tags for all child routes starting at this router AddTags(tags []string) // Sets the responses for all child routes starting at this router // This is similar to router.SetOperation(api.Operation{Responses: responses}). SetResponses(responses api.Responses) // Adds responses for all child routes starting at this router. AddResponses(responses api.Responses) // Adds a response for all child routes starting at this router. AddResponse(code string, response api.Response) // Gets or creates a scope for the given request if it doesn't exist yet. GetScope(response http.ResponseWriter, request *http.Request) (scope *deps.Scope, freeScope bool) // Use appends one or more middlewares onto the Router stack. // A middleware is a dependency injectable function. // The function has access to the request, response, scope, and any other // injectable request values. The values applied to the scope here will // be passed down to lower routes and can be injected in their functions. // If the function has problems injecting arguments or returns any errors // then the next handler in the stack will not be invoked and the error // will be handled like any other error. Use(middlewares ...any) // With adds inline middlewares for an endpoint handler and returns a // new router at the same URL. With(middlewares ...any) Router // Group adds a new inline-Router along the current routing // path, with a fresh middleware stack for the inline-Router. Group(fn func(r Router)) Router // Route mounts a sub-Router along a `pattern` string. Route(pattern string, fn func(r Router)) Router // Handle and HandleFunc adds routes for `pattern` that matches all HTTP methods. HandleFunc(pattern string, fn any, operations ...api.Operation) *api.Path // Method and MethodFunc adds routes for `pattern` that matches // the `method` HTTP method. MethodFunc(method, pattern string, fn any, operations ...api.Operation) RouterOperation // HTTP-method routing along `pattern` Connect(pattern string, fn any) Delete(pattern string, fn any, operations ...api.Operation) RouterOperation Get(pattern string, fn any, operations ...api.Operation) RouterOperation Head(pattern string, fn any, operations ...api.Operation) RouterOperation Options(pattern string, fn any, operations ...api.Operation) RouterOperation Patch(pattern string, fn any, operations ...api.Operation) RouterOperation Post(pattern string, fn any, operations ...api.Operation) RouterOperation Put(pattern string, fn any, operations ...api.Operation) RouterOperation Trace(pattern string, fn any, operations ...api.Operation) RouterOperation // NotFound defines a handler to respond whenever a route could // not be found. NotFound(fn any) // MethodNotAllowed defines a handler to respond whenever a method is // not allowed. MethodNotAllowed(fn any) }
Router with OpenAPI integration and dependency injection
type RouterOperation ¶ added in v0.2.0
type RouterOperation interface { // The operation documentation. Operation() *api.Operation // The router of the operation Router() Router // Adds the given type/instance as an input (body, param, query, header) to the operation. Input(input ...any) // Adds the given type/instance as a response type to the operation. Output(output ...any) }
A router operation
type ServiceUnavailable ¶
type ServiceUnavailable[V any] struct { }
A 503 response.
func NewServiceUnavailable ¶
func NewServiceUnavailable[V any](result V) *ServiceUnavailable[V]
func (ServiceUnavailable[V]) APIName ¶ added in v0.3.4
func (err ServiceUnavailable[V]) APIName() string
func (ServiceUnavailable[V]) APISchemaType ¶ added in v0.3.4
func (err ServiceUnavailable[V]) APISchemaType() any
func (ServiceUnavailable[V]) Error ¶
func (err ServiceUnavailable[V]) Error() string
func (ServiceUnavailable[V]) HTTPStatus ¶
func (err ServiceUnavailable[V]) HTTPStatus() int
func (ServiceUnavailable[V]) HTTPStatuses ¶
func (err ServiceUnavailable[V]) HTTPStatuses() []int
func (ServiceUnavailable[V]) MarshalJSON ¶
func (err ServiceUnavailable[V]) MarshalJSON() ([]byte, error)
func (*ServiceUnavailable[V]) UnmarshalJSON ¶
func (err *ServiceUnavailable[V]) UnmarshalJSON(data []byte) error
type Site ¶
type Site struct { Open *api.Builder Scope *deps.Scope ServeJSON bool ServeXML bool // contains filtered or unexported fields }
The main router for rez. Can only be created with rez.New. All sub routers created are also a Site.
func (*Site) AddResponse ¶
Adds responses for all child routes starting at this router.
func (*Site) AddResponses ¶
Adds responses for all child routes starting at this router.
func (*Site) BuildDocument ¶
func (*Site) CreatePath ¶
Gets the path define at the given pattern, creating it if need be.
func (*Site) DefineBody ¶
Adds the types of the given values as injectable request bodies. This avoids the necessity of rez.Body or rez.Request. If any of the values/types have already been defined this will cause a panic.
func (*Site) DefineHeader ¶
Adds the types of the given values as injectable header values. This avoids the necessity of rez.Header. If any of the values/types have already been defined this will cause a panic.
func (*Site) DefinePath ¶
Adds the types of the given values as injectable path parameters. This avoids the necessity of rez.Param or rez.Request. If any of the values/types have already been defined this will cause a panic.
func (*Site) DefineQuery ¶
Adds the types of the given values as injectable query parameters. This avoids the necessity of rez.Query or rez.Request. If any of the values/types have already been defined this will cause a panic.
func (*Site) EnableValidation ¶
Enables or disables validation for all routes in this router or sub routers created after this is set. By default validation is not enabled.
func (*Site) GetOperations ¶
Gets the base operation which has all inherited tags and responses set at the current router.
func (*Site) GetScope ¶
func (site *Site) GetScope(response http.ResponseWriter, request *http.Request) (requestScope *deps.Scope, freeScope bool)
Gets or creates a scope for the given request if it doesn't exist yet.
func (*Site) Group ¶
Group adds a new inline-Router along the current routing path, with a fresh middleware stack for the inline-Router.
func (*Site) HandleError ¶
func (site *Site) HandleError(err error, response http.ResponseWriter, request *http.Request, scope *deps.Scope) error
Handles the given error if its a HandledError, is handled by the error handler, or is handled with default behavior.
func (*Site) HandleFunc ¶
Handle and HandleFunc adds routes for `pattern` that matches all HTTP methods.
func (*Site) MethodFunc ¶
func (site *Site) MethodFunc(method string, pattern string, fn any, operations ...api.Operation) RouterOperation
Method and MethodFunc adds routes for `pattern` that matches the `method` HTTP method.
func (*Site) MethodNotAllowed ¶
func (*Site) PrintPaths ¶
func (site *Site) PrintPaths()
func (*Site) Send ¶
func (site *Site) Send(response any, w http.ResponseWriter) error
Sends the response to the writer.
func (*Site) SendAny ¶
func (site *Site) SendAny(response []byte, w http.ResponseWriter, status int, contentType api.ContentType)
func (*Site) ServeOpenJSON ¶
func (*Site) ServeRedoc ¶
func (*Site) ServeSwaggerUI ¶
func (*Site) SetErrorHandler ¶
func (site *Site) SetErrorHandler(handler ErrorHandler)
Sets the error handler at this router and all sub routers created after this is set.
func (*Site) SetInternalErrorHandler ¶
func (site *Site) SetInternalErrorHandler(handle InternalErrorHandler)
Sets the handler for errors we received outside of responding to the client.
func (*Site) SetOperations ¶
Sets the base operation. All sub routes will inherit the properties on the base operation.
func (*Site) SetResponses ¶
Sets the tags for all child routes starting at this router
func (*Site) SetValidationOptions ¶
func (site *Site) SetValidationOptions(valueOrType any, options ValidationOptions)
Sets the validation options for the type or value's type.
func (*Site) UpdateOperations ¶
Updates the base operation (merges in given properties into existing base operation). All sub routes will inherit the properties on the base operation.
func (*Site) UpdatePath ¶
Gets the path defined at the given pattern, if any
func (Site) ValidationOptions ¶
func (site Site) ValidationOptions(typ reflect.Type) ValidationOptions
Returns the validation options specified for the given type.
type SiteOperation ¶ added in v0.2.0
type SiteOperation struct {
// contains filtered or unexported fields
}
An operation for a site.
func (SiteOperation) Input ¶ added in v0.2.0
func (op SiteOperation) Input(input ...any)
func (SiteOperation) Operation ¶ added in v0.2.0
func (op SiteOperation) Operation() *api.Operation
func (SiteOperation) Output ¶ added in v0.2.0
func (op SiteOperation) Output(output ...any)
func (SiteOperation) Router ¶ added in v0.2.0
func (op SiteOperation) Router() Router
type TooManyRequests ¶
type TooManyRequests[V any] struct { Result V }
A 429 response.
func NewTooManyRequests ¶
func NewTooManyRequests[V any](result V) *TooManyRequests[V]
func (TooManyRequests[V]) APIName ¶ added in v0.3.4
func (err TooManyRequests[V]) APIName() string
func (TooManyRequests[V]) APISchemaType ¶ added in v0.3.4
func (err TooManyRequests[V]) APISchemaType() any
func (TooManyRequests[V]) Error ¶
func (err TooManyRequests[V]) Error() string
func (TooManyRequests[V]) HTTPStatus ¶
func (err TooManyRequests[V]) HTTPStatus() int
func (TooManyRequests[V]) HTTPStatuses ¶
func (err TooManyRequests[V]) HTTPStatuses() []int
func (TooManyRequests[V]) MarshalJSON ¶
func (err TooManyRequests[V]) MarshalJSON() ([]byte, error)
func (*TooManyRequests[V]) UnmarshalJSON ¶
func (err *TooManyRequests[V]) UnmarshalJSON(data []byte) error
type Unauthorized ¶
type Unauthorized[V any] struct { }
A 401 response.
func NewUnauthorized ¶
func NewUnauthorized[V any](result V) *Unauthorized[V]
func (Unauthorized[V]) APIName ¶ added in v0.3.4
func (err Unauthorized[V]) APIName() string
func (Unauthorized[V]) APISchemaType ¶ added in v0.3.4
func (err Unauthorized[V]) APISchemaType() any
func (Unauthorized[V]) Error ¶
func (err Unauthorized[V]) Error() string
func (Unauthorized[V]) HTTPStatus ¶
func (err Unauthorized[V]) HTTPStatus() int
func (Unauthorized[V]) HTTPStatuses ¶
func (err Unauthorized[V]) HTTPStatuses() []int
func (Unauthorized[V]) MarshalJSON ¶
func (err Unauthorized[V]) MarshalJSON() ([]byte, error)
func (*Unauthorized[V]) UnmarshalJSON ¶
func (err *Unauthorized[V]) UnmarshalJSON(data []byte) error
type Validation ¶
type Validation struct { // The path to the offending value. Path []string `json:"path,omitempty"` // The name of the schema, if any. Schema *string `json:"schema,omitempty"` // The validation rule that caused the failure. Rule ValidationRule `json:"rule,omitempty"` // A message with more details. Message string `json:"message,omitempty"` }
A validation failure
type ValidationOptions ¶
type ValidationOptions struct { // If all validation should be skipped. Skip bool // If format is set, if the string representation of the // value should be validated against the specified format (if its supported). EnforceFormat bool // If specifying a deprecated value should result in a validation error. FailDeprecated bool // If validation should be skipped for deprecated schemas SkipDeprecated bool }
Options for validating a particular type.
type ValidationProvider ¶
type ValidationProvider interface {
ValidationOptions(reflect.Type) ValidationOptions
}
An interface which helps the validation process.
type ValidationRule ¶
type ValidationRule string
A rule that was broken that caused the validation failure.
const ( ValidationRuleType ValidationRule = "type" ValidationRuleMultipleOf ValidationRule = "multipleOf" ValidationRuleMaximum ValidationRule = "maximum" ValidationRuleMinimum ValidationRule = "minimum" ValidationRuleMaxLength ValidationRule = "maxLength" ValidationRuleMinLength ValidationRule = "minLength" ValidationRulePattern ValidationRule = "pattern" ValidationRuleFormat ValidationRule = "format" ValidationRuleMaxItems ValidationRule = "maxItems" ValidationRuleMinItems ValidationRule = "minItems" ValidationRuleUniqueItems ValidationRule = "uniqueItems" ValidationRuleMaxProperties ValidationRule = "maxProperties" ValidationRuleMinProperties ValidationRule = "minProperties" ValidationRuleRequired ValidationRule = "required" ValidationRuleDeprecated ValidationRule = "deprecated" ValidationRuleEnum ValidationRule = "enum" ValidationRuleNullable ValidationRule = "nullable" ValidationRuleOneOf ValidationRule = "oneOf" ValidationRuleAllOf ValidationRule = "allOf" ValidationRuleAnyOf ValidationRule = "anyOf" ValidationRuleNot ValidationRule = "not" ValidationRuleCustom ValidationRule = "custom" )
type Validator ¶
type Validator struct { Path []string `json:"-"` Validations *[]Validation `json:"validations"` Provider ValidationProvider `json:"-"` Scope *deps.Scope `json:"-"` }
A validator for a specific element being validated. Validators all share Validations and Providers. Adding a validation to one adds it to the others.
func NewValidator ¶
func NewValidator(provider ValidationProvider, scope *deps.Scope) *Validator
Creates a new validator for the given provider and scope.
func (*Validator) Add ¶
func (v *Validator) Add(msg Validation)
Adds a validation error to the validator. If no path is specified on the validation then the path of the validator is applied.
func (*Validator) Attach ¶
Attaches a validtor to this validator by adding its validations to this one.
func (Validator) HTTPStatus ¶
400 is used, this also signals to return the error as JSON.
func (Validator) HTTPStatuses ¶
func (Validator) HasFailures ¶
Returns true if the validator has failures.