Documentation
¶
Index ¶
- Variables
- func AddRoute[I, O any](api advancedApi, r AdvancedRoute[I, O]) (err error)
- func Advanced(api *API) advancedApi
- func DELETE[I, O any](api *API, r Route[I, O]) (err error)
- func GET[I, O any](api *API, r Route[I, O]) (err error)
- func POST[I, O any](api *API, r Route[I, O]) (err error)
- func PUT[I, O any](api *API, r Route[I, O]) (err error)
- type API
- func (api *API) Close(grace ...time.Duration) error
- func (api *API) HasPermission(roles []string, perm security.Permission) bool
- func (api *API) ListenAndServe(addr string) error
- func (api *API) RegisterRoutes(types ...any) (err error)
- func (api *API) RegisterType(typs ...registry.TypeRegistrar) (err error)
- func (api *API) WriteOpenAPI(w io.Writer) error
- type AdvancedRoute
- type File
- type FileType
- type List
- type MultipartFile
- type Options
- type RawJSON
- type RequestCtx
- type Route
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.NewFrozenError("NOT_FOUND", "The API route could not be found", 404) ErrInvalidParams = errors.NewFrozenError("INVALID_PARAMS", "URL params count mismatch", 500) ErrUnknownError = errors.NewFrozenError("UNKNOWN_ERROR", "An unknown error occured", 500) )
API error
var ( ErrInvalidOpenAPI = errs.New("there must not be any existing operations in OpenAPI documentation") ErrMissingOpenAPI = errs.New("no OpenAPI documentation initialized") ErrMissingRoutePath = errs.New("missing route path") ErrMissingRouteHandler = errs.New("missing route handler") ErrMissingRouteMethod = errs.New("missing route method") )
Functions ¶
func AddRoute ¶
func AddRoute[I, O any](api advancedApi, r AdvancedRoute[I, O]) (err error)
Add an advanced route. This is more low-level without any real benefits, thus discouraged.
func DELETE ¶
Add a route with DELETE method. Input will be validated based on OpenAPI schema rules.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
func (*API) Close ¶
Close API for new requests, and close all current requests after specified grace period (default 3 seconds).
func (*API) HasPermission ¶ added in v0.21.0
func (api *API) HasPermission(roles []string, perm security.Permission) bool
func (*API) ListenAndServe ¶
Listen on the provided address (e.g. `localhost:3000`).
func (*API) RegisterRoutes ¶
Register a group of routes. Any exported methods with a signature of `func(api *papi.API) error` will be called. These methods should call either `papi.GET`, `papi.PUT`, `papi.POST`, or `papi.DELETE`.
func (*API) RegisterType ¶
func (api *API) RegisterType(typs ...registry.TypeRegistrar) (err error)
Register a custom type, that will override any defaults.
type AdvancedRoute ¶
type File ¶ added in v0.10.0
type File[T FileType] struct { // contains filtered or unexported fields }
func (*File[T]) SetFilename ¶ added in v0.11.0
func (File[T]) TypeDescription ¶ added in v0.10.0
func (File[T]) TypeDescription(reg *registry.Registry) registry.TypeDescription
TypeDescription implements registry.TypeDescriber.
type List ¶
type List[T any] struct { // contains filtered or unexported fields }
A streaming list response.
func (List[T]) TypeDescription ¶
func (List[T]) TypeDescription(reg *registry.Registry) registry.TypeDescription
TypeDescription implements registry.TypeDescriber.
type MultipartFile ¶ added in v0.18.0
type MultipartFile struct {
// contains filtered or unexported fields
}
func (MultipartFile) TypeDescription ¶ added in v0.18.0
func (m MultipartFile) TypeDescription(reg *registry.Registry) registry.TypeDescription
TypeDescription implements registry.TypeDescriber.
type Options ¶
type Options struct { // An optional (but recommended) OpenAPI document. Provided document must be unused, a.k.a. have no registered operations, // and will be filled with documentation for all routes. OpenAPI *openapi.Document // Any errors occured will be passed through this callback, where it has the chance to transform the error to an // `errors.ErrorDocumentor` (if not already). Any error that isn't transformed will be replaced with a general error message. TransformError func(err error) errors.ErrorDocumentor // Header for Cross-Origin Resource Sharing (CORS). CORS string }
API options.
type RawJSON ¶ added in v0.12.0
type RawJSON []byte
func (RawJSON) MarshalJSON ¶ added in v0.12.5
MarshalJSON implements json.Marshaler.
func (RawJSON) TypeDescription ¶ added in v0.12.0
func (RawJSON) TypeDescription(reg *registry.Registry) registry.TypeDescription
TypeDescription implements registry.TypeDescriber.
func (*RawJSON) UnmarshalJSON ¶ added in v0.12.5
UnmarshalJSON implements json.Unmarshaler.
type Route ¶
type Route[I any, O any] struct { // Mandatory route path. Can contain `{params}`. Path string // An optional description of the route (longer than the `Summary`). Description string // Mandatory handler that will be called for the route. Handler func(c *RequestCtx, in *I, out *O) error // Whether the route is deprecated and discouraged. Deprecated bool }
Route information.