aio

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 18 Imported by: 0

README

aio

all-in-one REST API framework for Go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadRequest                   error = Error(http.StatusBadRequest, http.StatusText(http.StatusBadRequest), nil)
	ErrUnauthorized                 error = Error(http.StatusUnauthorized, http.StatusText(http.StatusUnauthorized), nil)
	ErrPaymentRequired              error = Error(http.StatusPaymentRequired, http.StatusText(http.StatusPaymentRequired), nil)
	ErrForbidden                    error = Error(http.StatusForbidden, http.StatusText(http.StatusForbidden), nil)
	ErrNotFound                     error = Error(http.StatusNotFound, http.StatusText(http.StatusNotFound), nil)
	ErrMethodNotAllowed             error = Error(http.StatusMethodNotAllowed, http.StatusText(http.StatusMethodNotAllowed), nil)
	ErrNotAcceptable                error = Error(http.StatusNotAcceptable, http.StatusText(http.StatusNotAcceptable), nil)
	ErrProxyAuthRequired            error = Error(http.StatusProxyAuthRequired, http.StatusText(http.StatusProxyAuthRequired), nil)
	ErrRequestTimeout               error = Error(http.StatusRequestTimeout, http.StatusText(http.StatusRequestTimeout), nil)
	ErrConflict                     error = Error(http.StatusConflict, http.StatusText(http.StatusConflict), nil)
	ErrGone                         error = Error(http.StatusGone, http.StatusText(http.StatusGone), nil)
	ErrLengthRequired               error = Error(http.StatusLengthRequired, http.StatusText(http.StatusLengthRequired), nil)
	ErrPreconditionFailed           error = Error(http.StatusPreconditionFailed, http.StatusText(http.StatusPreconditionFailed), nil)
	ErrRequestEntityTooLarge        error = Error(http.StatusRequestEntityTooLarge, http.StatusText(http.StatusRequestEntityTooLarge), nil)
	ErrRequestURITooLong            error = Error(http.StatusRequestURITooLong, http.StatusText(http.StatusRequestURITooLong), nil)
	ErrUnsupportedMediaType         error = Error(http.StatusUnsupportedMediaType, http.StatusText(http.StatusUnsupportedMediaType), nil)
	ErrRequestedRangeNotSatisfiable error = Error(http.StatusRequestedRangeNotSatisfiable, http.StatusText(http.StatusRequestedRangeNotSatisfiable), nil)
	ErrExpectationFailed            error = Error(http.StatusExpectationFailed, http.StatusText(http.StatusExpectationFailed), nil)
	ErrTeapot                       error = Error(http.StatusTeapot, http.StatusText(http.StatusTeapot), nil)
	ErrMisdirectedRequest           error = Error(http.StatusMisdirectedRequest, http.StatusText(http.StatusMisdirectedRequest), nil)
	ErrUnprocessableEntity          error = Error(http.StatusUnprocessableEntity, http.StatusText(http.StatusUnprocessableEntity), nil)
	ErrLocked                       error = Error(http.StatusLocked, http.StatusText(http.StatusLocked), nil)
	ErrFailedDependency             error = Error(http.StatusFailedDependency, http.StatusText(http.StatusFailedDependency), nil)
	ErrTooEarly                     error = Error(http.StatusTooEarly, http.StatusText(http.StatusTooEarly), nil)
	ErrUpgradeRequired              error = Error(http.StatusUpgradeRequired, http.StatusText(http.StatusUpgradeRequired), nil)
	ErrPreconditionRequired         error = Error(http.StatusPreconditionRequired, http.StatusText(http.StatusPreconditionRequired), nil)
	ErrTooManyRequests              error = Error(http.StatusTooManyRequests, http.StatusText(http.StatusTooManyRequests), nil)
	ErrRequestHeaderFieldsTooLarge  error = Error(http.StatusRequestHeaderFieldsTooLarge, http.StatusText(http.StatusRequestHeaderFieldsTooLarge), nil)
	ErrUnavailableForLegalReasons   error = Error(http.StatusUnavailableForLegalReasons, http.StatusText(http.StatusUnavailableForLegalReasons), nil)

	ErrInternalServerError           error = Error(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError), nil)
	ErrNotImplemented                error = Error(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented), nil)
	ErrBadGateway                    error = Error(http.StatusBadGateway, http.StatusText(http.StatusBadGateway), nil)
	ErrServiceUnavailable            error = Error(http.StatusServiceUnavailable, http.StatusText(http.StatusServiceUnavailable), nil)
	ErrGatewayTimeout                error = Error(http.StatusGatewayTimeout, http.StatusText(http.StatusGatewayTimeout), nil)
	ErrHTTPVersionNotSupported       error = Error(http.StatusHTTPVersionNotSupported, http.StatusText(http.StatusHTTPVersionNotSupported), nil)
	ErrVariantAlsoNegotiates         error = Error(http.StatusVariantAlsoNegotiates, http.StatusText(http.StatusVariantAlsoNegotiates), nil)
	ErrInsufficientStorage           error = Error(http.StatusInsufficientStorage, http.StatusText(http.StatusInsufficientStorage), nil)
	ErrLoopDetected                  error = Error(http.StatusLoopDetected, http.StatusText(http.StatusLoopDetected), nil)
	ErrNotExtended                   error = Error(http.StatusNotExtended, http.StatusText(http.StatusNotExtended), nil)
	ErrNetworkAuthenticationRequired error = Error(http.StatusNetworkAuthenticationRequired, http.StatusText(http.StatusNetworkAuthenticationRequired), nil)
)

Functions

func WithAPIKeySecurity

func WithAPIKeySecurity(name, paramName string, in ParameterLocation, opts ...securitySchemeOpt) oapiOpt

WithAPIKeySecurity declares an API key security scheme named name, with the key passed in the parameter paramName located in in (ParameterLocationHeader, ParameterLocationQuery or ParameterLocationCookie).

func WithBasicSecurity

func WithBasicSecurity(name string, opts ...securitySchemeOpt) oapiOpt

WithBasicSecurity declares an HTTP Basic authentication security scheme named name.

func WithBearerSecurity

func WithBearerSecurity(name, bearerFormat string, opts ...securitySchemeOpt) oapiOpt

WithBearerSecurity declares an HTTP Bearer authentication security scheme named name. bearerFormat is an optional hint of the token format (e.g. "JWT").

func WithDebug

func WithDebug(debug bool) appOpt

WithDebug sends the error message in ProblemDetails.Detail. Without it Detail is always empty, so internal errors don't leak to the client.

func WithDeprecated

func WithDeprecated() endpointOpt

func WithDescription

func WithDescription(description string) endpointOpt

func WithEndpointOptions

func WithEndpointOptions(endpointOpts ...endpointOpt) appOpt

WithEndpointOptions applies endpointOpts to every endpoint of the App, including the ones in groups. They are applied before the options passed when registering the endpoint.

func WithEnumType

func WithEnumType[T ~string | ~int | ~uint](values []T) oapiOpt

WithEnumType declares T as an enum with the given values. Every occurrence of T in request and response types is described in the OpenAPI document as a reference to a component schema listing the values.

func WithErrorStatusCodes

func WithErrorStatusCodes(statusCodes ...int) endpointOpt

WithErrorStatusCodes declares HTTP status codes the endpoint may return an error with. Each of them is described in OpenAPI as a ProblemDetails response.

func WithHTTPSecurity

func WithHTTPSecurity(name, scheme string, opts ...securitySchemeOpt) oapiOpt

WithHTTPSecurity declares an HTTP authentication security scheme named name. scheme is an HTTP authentication scheme from the IANA registry (e.g. "basic", "bearer", "digest").

func WithMiddlewares

func WithMiddlewares(middlewares ...Middleware) endpointOpt

WithMiddlewares adds middlewares applied only to this endpoint. They run after the App and Group middlewares, right before the handler.

func WithMutualTLSSecurity

func WithMutualTLSSecurity(name string, opts ...securitySchemeOpt) oapiOpt

WithMutualTLSSecurity declares a mutual TLS security scheme named name.

func WithOAuth2AuthorizationCodeFlow

func WithOAuth2AuthorizationCodeFlow(authorizationURL, tokenURL string, scopes map[string]string, opts ...oauth2FlowOpt) securitySchemeOpt

WithOAuth2AuthorizationCodeFlow declares the OAuth2 Authorization Code flow. Applies only to WithOAuth2Security. scopes maps scope names to their short descriptions and may be empty.

func WithOAuth2ClientCredentialsFlow

func WithOAuth2ClientCredentialsFlow(tokenURL string, scopes map[string]string, opts ...oauth2FlowOpt) securitySchemeOpt

WithOAuth2ClientCredentialsFlow declares the OAuth2 Client Credentials flow. Applies only to WithOAuth2Security. scopes maps scope names to their short descriptions and may be empty.

func WithOAuth2DeviceAuthorizationFlow

func WithOAuth2DeviceAuthorizationFlow(deviceAuthorizationURL, tokenURL string, scopes map[string]string, opts ...oauth2FlowOpt) securitySchemeOpt

WithOAuth2DeviceAuthorizationFlow declares the OAuth2 Device Authorization flow (RFC 8628). Applies only to WithOAuth2Security. scopes maps scope names to their short descriptions and may be empty.

func WithOAuth2ImplicitFlow

func WithOAuth2ImplicitFlow(authorizationURL string, scopes map[string]string, opts ...oauth2FlowOpt) securitySchemeOpt

WithOAuth2ImplicitFlow declares the OAuth2 Implicit flow. Applies only to WithOAuth2Security. scopes maps scope names to their short descriptions and may be empty.

func WithOAuth2MetadataURL

func WithOAuth2MetadataURL(url string) securitySchemeOpt

WithOAuth2MetadataURL sets the URL of the OAuth2 authorization server metadata (RFC 8414). Applies only to WithOAuth2Security.

func WithOAuth2PasswordFlow

func WithOAuth2PasswordFlow(tokenURL string, scopes map[string]string, opts ...oauth2FlowOpt) securitySchemeOpt

WithOAuth2PasswordFlow declares the OAuth2 Resource Owner Password flow. Applies only to WithOAuth2Security. scopes maps scope names to their short descriptions and may be empty.

func WithOAuth2RefreshURL

func WithOAuth2RefreshURL(url string) oauth2FlowOpt

WithOAuth2RefreshURL sets the URL used to obtain refresh tokens in an OAuth2 flow.

func WithOAuth2Security

func WithOAuth2Security(name string, opts ...securitySchemeOpt) oapiOpt

WithOAuth2Security declares an OAuth2 security scheme named name. The supported flows are declared with the WithOAuth2*Flow options.

func WithOpenAPIContact

func WithOpenAPIContact(name, url, email string) oapiOpt

func WithOpenAPIDescription

func WithOpenAPIDescription(desc string) oapiOpt

func WithOpenAPILicense

func WithOpenAPILicense(name, url string) oapiOpt

func WithOpenAPIOptions

func WithOpenAPIOptions(openapiOpts ...oapiOpt) appOpt

func WithOpenAPIPath

func WithOpenAPIPath(openAPIPath string) oapiOpt

func WithOpenIDConnectSecurity

func WithOpenIDConnectSecurity(name, url string, opts ...securitySchemeOpt) oapiOpt

WithOpenIDConnectSecurity declares an OpenID Connect security scheme named name. url points to the OpenID Connect Discovery document.

func WithSecurity

func WithSecurity(name string, scopes ...string) endpointOpt

WithSecurity declares in OpenAPI that the endpoint requires the security scheme named name, declared before with one of the With...Security options. scopes are needed only for OAuth2 and OpenID Connect. Every call adds an alternative - the client has to satisfy only one of them.

func WithSecuritySchemeDeprecated

func WithSecuritySchemeDeprecated() securitySchemeOpt

WithSecuritySchemeDeprecated marks a security scheme as deprecated.

func WithSecuritySchemeDescription

func WithSecuritySchemeDescription(desc string) securitySchemeOpt

WithSecuritySchemeDescription sets the description of a security scheme.

func WithSummary

func WithSummary(summary string) endpointOpt

func WithTags

func WithTags(tags ...string) endpointOpt

func WithUIPath

func WithUIPath(uiPath string) oapiOpt

func WithValidator

func WithValidator(validate *validator.Validate) appOpt

func WithoutOpenAPI

func WithoutOpenAPI() oapiOpt

Types

type App

type App struct {
	// contains filtered or unexported fields
}

func New

func New(name string, version string, appOpts ...appOpt) *App

func (*App) Delete

func (app *App) Delete[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*App) DeleteStd

func (app *App) DeleteStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*App) ErrorHandler

func (app *App) ErrorHandler(w http.ResponseWriter, r *http.Request, err error)

func (*App) Get

func (app *App) Get[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*App) GetStd

func (app *App) GetStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*App) Group

func (app *App) Group(path string) *Group

func (*App) Head

func (app *App) Head[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*App) HeadStd

func (app *App) HeadStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*App) Options

func (app *App) Options[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*App) OptionsStd

func (app *App) OptionsStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*App) Patch

func (app *App) Patch[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*App) PatchStd

func (app *App) PatchStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*App) Post

func (app *App) Post[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*App) PostStd

func (app *App) PostStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*App) Put

func (app *App) Put[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*App) PutStd

func (app *App) PutStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*App) Query

func (app *App) Query[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*App) QueryStd

func (app *App) QueryStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*App) Register

func (app *App) Register[In, Out any](method string, path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*App) RegisterStd

func (app *App) RegisterStd(method string, path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*App) Run

func (app *App) Run(addr string) error

func (*App) RunTLS

func (app *App) RunTLS(addr string, certFile string, keyFile string) error

func (*App) Trace

func (app *App) Trace[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*App) TraceStd

func (app *App) TraceStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*App) UseEndpointOptions

func (app *App) UseEndpointOptions(endpointOpts ...endpointOpt)

UseEndpointOptions adds endpointOpts to the endpoints and groups registered after the call. They are applied before the options passed when registering the endpoint.

func (*App) UseMiddleware

func (app *App) UseMiddleware(middlewares ...Middleware)

UseMiddleware adds middlewares to the endpoints and groups registered after the call.

type Empty

type Empty struct{}

type Endpoint

type Endpoint struct {
	// contains filtered or unexported fields
}

type Group

type Group struct {
	// contains filtered or unexported fields
}

func (*Group) Delete

func (g *Group) Delete[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*Group) DeleteStd

func (g *Group) DeleteStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*Group) Get

func (g *Group) Get[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*Group) GetStd

func (g *Group) GetStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*Group) Group

func (g *Group) Group(path string) *Group

func (*Group) Head

func (g *Group) Head[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*Group) HeadStd

func (g *Group) HeadStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*Group) Options

func (g *Group) Options[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*Group) OptionsStd

func (g *Group) OptionsStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*Group) Patch

func (g *Group) Patch[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*Group) PatchStd

func (g *Group) PatchStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*Group) Post

func (g *Group) Post[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*Group) PostStd

func (g *Group) PostStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*Group) Put

func (g *Group) Put[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*Group) PutStd

func (g *Group) PutStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*Group) Query

func (g *Group) Query[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*Group) QueryStd

func (g *Group) QueryStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*Group) Register

func (g *Group) Register[In, Out any](method string, path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*Group) RegisterStd

func (g *Group) RegisterStd(method string, path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*Group) Trace

func (g *Group) Trace[In, Out any](path string, handlerFunc func(context.Context, In) (Out, error), endpointOpts ...endpointOpt)

func (*Group) TraceStd

func (g *Group) TraceStd(path string, handlerFunc HandlerFunc, endpointOpts ...endpointOpt)

func (*Group) UseEndpointOptions

func (g *Group) UseEndpointOptions(endpointOpts ...endpointOpt)

UseEndpointOptions adds endpointOpts to the endpoints and child groups registered after the call. They are applied before the options passed when registering the endpoint.

func (*Group) UseMiddleware

func (g *Group) UseMiddleware(middlewares ...Middleware)

UseMiddleware adds middlewares to the endpoints and child groups registered after the call.

type HandlerFunc

type HandlerFunc func(w http.ResponseWriter, r *http.Request) error

HandlerFunc is an http.HandlerFunc that returns an error instead of writing it. The error is turned into a response by App.ErrorHandler.

type Middleware

type Middleware func(next HandlerFunc) HandlerFunc

type OpenAPIFormatter

type OpenAPIFormatter interface {
	OpenAPIFormat() string
}

OpenAPIFormatter overrides the OpenAPI data format (e.g. "uuid", "date", "email") of a custom type. The method is called on a zero value of the type.

type OpenAPITyper

type OpenAPITyper interface {
	OpenAPIType() string
}

OpenAPITyper overrides the OpenAPI data type (e.g. "string", "integer") of a custom type. The method is called on a zero value of the type.

type ParameterLocation

type ParameterLocation = openapi.ParameterLocation

ParameterLocation is the location of a parameter in an HTTP request.

const (
	ParameterLocationPath   ParameterLocation = openapi.ParameterLocationPath
	ParameterLocationQuery  ParameterLocation = openapi.ParameterLocationQuery
	ParameterLocationHeader ParameterLocation = openapi.ParameterLocationHeader
	ParameterLocationCookie ParameterLocation = openapi.ParameterLocationCookie
)

type ProblemDetails

type ProblemDetails struct {
	Title  string `json:"title" xml:"title"`
	Status int    `json:"status" xml:"status"`
	Detail string `json:"detail,omitempty" xml:"detail,omitempty"`
}

func Error

func Error(status int, title string, err error) ProblemDetails

func (ProblemDetails) Error

func (pd ProblemDetails) Error() string

Directories

Path Synopsis
examples
simple command
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL