Documentation ¶
Index ¶
- Constants
- func Authenticate(c Context) error
- func Body[T any](c Context) (*T, error)
- func BodyP[T any](c Context) *T
- func CreateChiMiddleware(fn MiddlewareHandler, mwCtx Context) func(http.Handler) http.Handler
- func CreateLogger(level ...zerolog.Level)
- func SetDefaultMiddleware(r *chi.Mux, opts *Options) error
- func SetMetricsMiddleware(r *chi.Mux, opts *Options) error
- func SetMiddleware(r *chi.Mux, middleware ...func(http.Handler) http.Handler) error
- func SetRequestLogger(r *chi.Mux, opts *Options) error
- func SetTracingMiddleware(r *chi.Mux, opts *Options) error
- type AuthConfiguration
- type AuthOptions
- type AuthServerOptions
- type Claims
- type Context
- type Error
- type Group
- type Handler
- type JSONObject
- type MiddlewareHandler
- type OpenAPIOptions
- type Options
- type ParamLocation
- type Parameter
- type Params
- type Response
- type Route
- func Delete[T any](path string, fn Handler) *Route
- func Get[T any](path string, fn Handler) *Route
- func NewRoute(path, method string, spec *Spec, fn Handler) *Route
- func Patch[B any, T any](path string, fn Handler) *Route
- func Post[B any, T any](path string, fn Handler) *Route
- func Put[B any, T any](path string, fn Handler) *Route
- func (r *Route) Auth() *Route
- func (r *Route) Desc(desc string) *Route
- func (r *Route) KeyAuth() *Route
- func (r *Route) Middleware(middleware ...MiddlewareHandler) *Route
- func (r *Route) Query(params any) *Route
- func (r *Route) Role(role ...string) *Route
- func (r *Route) Spec() *Spec
- func (r *Route) Tag(tags ...string) *Route
- func (r *Route) Title(title string) *Route
- func (r *Route) With(opts ...SpecOpt) *Route
- type Server
- type ServerConfiguration
- func WithAuth(cfgs ...AuthConfiguration) ServerConfiguration
- func WithDefaultMiddleware() ServerConfiguration
- func WithFrontend(fe any) ServerConfiguration
- func WithID(id string) ServerConfiguration
- func WithMetrics(uri ...string) ServerConfiguration
- func WithMiddleware(middleware ...func(http.Handler) http.Handler) ServerConfiguration
- func WithOpenAPI(title, desc, version string) ServerConfiguration
- func WithPort(port int) ServerConfiguration
- func WithRapiDoc() ServerConfiguration
- func WithReflector(ref *openapi3.Reflector) ServerConfiguration
- func WithRequestLogging() ServerConfiguration
- func WithRouter(r *chi.Mux) ServerConfiguration
- func WithStripPrefixes(prefixes ...string) ServerConfiguration
- func WithSwagger() ServerConfiguration
- func WithTracing(url ...string) ServerConfiguration
- type ServerOptions
- type Spec
- func DeleteOp(routePath string, res any, opts ...SpecOpt) *Spec
- func GetOp(routePath string, res any, opts ...SpecOpt) *Spec
- func Of(opts ...SpecOpt) *Spec
- func PatchOp(routePath string, body any, res any, opts ...SpecOpt) *Spec
- func PostOp(routePath string, body any, res any, opts ...SpecOpt) *Spec
- func PutOp(routePath string, body any, res any, opts ...SpecOpt) *Spec
- func (s *Spec) Build(ref *openapi3.Reflector) error
- func (s *Spec) FullPath() string
- func (s *Spec) FullRouterPath() string
- func (s *Spec) With(opts ...SpecOpt) *Spec
- func (s *Spec) WithAPIAuth() *Spec
- func (s *Spec) WithAuth() *Spec
- func (s *Spec) WithQueryObject(obj any) *Spec
- func (s *Spec) WithTags(tags ...string) *Spec
- func (s *Spec) WithValidation() *Spec
- type SpecOpt
- func WithBody(body any) SpecOpt
- func WithDescription(description string) SpecOpt
- func WithErrBadRequest(message ...string) SpecOpt
- func WithErrNotFound(message ...string) SpecOpt
- func WithError(errorCode int, message ...string) SpecOpt
- func WithForbidden(message ...string) SpecOpt
- func WithInternalError(message ...string) SpecOpt
- func WithMethod(m string) SpecOpt
- func WithOriginalPath(p string) SpecOpt
- func WithParam(loc ParamLocation, title string, paramType ...string) SpecOpt
- func WithParams(params []*Parameter) SpecOpt
- func WithPath(p string) SpecOpt
- func WithPathPrefix(p string) SpecOpt
- func WithResponse(body any, code ...int) SpecOpt
- func WithSummary(summary string) SpecOpt
- func WithTags(tags ...string) SpecOpt
- func WithUnauthorized(message ...string) SpecOpt
- type TelemetryOptions
- type WellKnown
Constants ¶
const ( ErrInternalServer = "E_INTERNAL_SERVER" ErrBadRequest = "E_BAD_REQ" ErrNotFound = "E_NOT_FOUND" )
Error constants
const ( TokenHeader = "Authorization" TokenCookie = "accessToken" RefreshTokenKey = "refreshToken" ExpiresInKey = "expiresIn" )
Various constants
Variables ¶
This section is empty.
Functions ¶
func CreateChiMiddleware ¶
CreateChiMiddleware ...
func SetDefaultMiddleware ¶
SetDefaultMiddleware ...
func SetMetricsMiddleware ¶
SetMetricsMiddleware enables Prometheus endpoint
func SetMiddleware ¶
SetMiddleware enables setting additional middleware
func SetRequestLogger ¶
SetRequestLogger enables request logging
func SetTracingMiddleware ¶
SetTracingMiddleware enables OTEL tracing
Types ¶
type AuthConfiguration ¶
type AuthConfiguration func(auth *AuthOptions) error
AuthConfiguration ...
func WithAuthClient ¶
func WithAuthClient(clientID string, secret ...string) AuthConfiguration
WithAuthClient sets oidc client and secret if present
func WithCookieAuth ¶
func WithCookieAuth() AuthConfiguration
WithCookieAuth enables reading auth data from cookies
type AuthOptions ¶
type AuthOptions struct { AuthServerOptions *AuthServerOptions ClientID string Secret string AuthCookie bool SecureAuthCookie bool APIKeyAuth bool }
AuthOptions ...
type AuthServerOptions ¶
type AuthServerOptions struct { ServerURL string WellKnownURL string TokenURI string AuthURI string RefreshURI string Realm string RedirectURL string ClientRedirectURL string }
AuthServerOptions ...
type Claims ¶
type Claims struct { AuthTime int `json:"auth_time"` Jti string `json:"jti"` Iss string `json:"iss"` Sub string `json:"sub"` Typ string `json:"typ"` Azp string `json:"azp"` SessionState string `json:"session_state"` Acr string `json:"acr"` AllowedOrigins []string `json:"allowed-origins"` RealmAccess struct { Roles []string `json:"roles"` } `json:"realm_access"` ResourceAccess struct { Account struct { Roles []string `json:"roles"` } `json:"account"` } `json:"resource_access"` Scope string `json:"scope"` Sid string `json:"sid"` EmailVerified bool `json:"email_verified"` Name string `json:"name"` PreferredUsername string `json:"preferred_username"` GivenName string `json:"given_name"` FamilyName string `json:"family_name"` Email string `json:"email"` }
Claims ...
type Context ¶
type Context interface { // Param returns all path params Param(id string) string // Query returns all query params Query(id string) string // Headers returns all headers Headers() Params // Body returns the request body Body() any // BindBody binds the body value to a struct BindBody(to any) error // BindBodyP binds the body or panics BindBodyP(to any) any // Raw handles http.Handler requests Raw(http.Handler) error // JSON returns JSON reply JSON(body any, statusCode ...int) error // Error returns Error reply Error(body any, statusCode ...int) error // Status sends an empty reply with specified status code Status(statusCode int) error // ResponseBody ... ResponseBody() any // StatusCode ... StatusCode() int // RequestError ... RequestError() any Request() *http.Request JWKS() jwk.Set SetJWKS(k jwk.Set) SetClaims(claims *Claims) Claims() *Claims Context() context.Context // HTTPHandler returns registered handler HTTPHandler() http.Handler }
Context ...
type Error ¶
type Error struct { ID int `json:"id,omitempty" yaml:"id,omitempty"` Code string `json:"code,omitempty" yaml:"code,omitempty"` Msg string `json:"message,omitempty" yaml:"message,omitempty"` AdditionalData *JSONObject `json:"data,omitempty" yaml:"data,omitempty"` Errors []any `json:"errors,omitempty" yaml:"errors,omitempty"` }
Error ...
func (*Error) Data ¶
func (e *Error) Data(data *JSONObject) *Error
Data sets the dao property for Error
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group ...
func (*Group) Middleware ¶
func (g *Group) Middleware(fns ...MiddlewareHandler) *Group
Middleware ...
type OpenAPIOptions ¶
type OpenAPIOptions struct { OASVersion string Servers []string Title string Description string Version string StripPrefixes []string Swagger bool Rapidoc bool }
OpenAPIOptions for initing openapi3.Reflector
type Options ¶
type Options struct { Server *ServerOptions AuthOptions *AuthOptions TelemetryOptions *TelemetryOptions OAS *OpenAPIOptions }
Options ...
type ParamLocation ¶
type ParamLocation string
ParamLocation is a type for parameter location (header, path, query)
const ( ParamLocationHeader ParamLocation = "header" ParamLocationPath ParamLocation = "path" ParamLocationQuery ParamLocation = "query" )
Possible values for ParamLocation
type Parameter ¶
type Parameter struct { Title string Type string Location ParamLocation }
Parameter definition
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route ...
func (*Route) Middleware ¶
func (r *Route) Middleware(middleware ...MiddlewareHandler) *Route
Middleware ...
type Server ¶
type Server interface { Route(route ...*Route) Server Group(path string, routes ...*Route) *Group Groups(groups ...*Group) Server Get(path string, handlerFn http.HandlerFunc) Server Post(path string, handlerFn http.HandlerFunc) Server Put(path string, handlerFn http.HandlerFunc) Server Patch(path string, handlerFn http.HandlerFunc) Server Delete(path string, handlerFn http.HandlerFunc) Server Listen() error }
Server ...
type ServerConfiguration ¶
type ServerConfiguration func(s *server) error
ServerConfiguration ...
func WithAuth ¶
func WithAuth(cfgs ...AuthConfiguration) ServerConfiguration
WithAuth configures OpenID connect
func WithDefaultMiddleware ¶
func WithDefaultMiddleware() ServerConfiguration
WithDefaultMiddleware enables default middleware
func WithFrontend ¶
func WithFrontend(fe any) ServerConfiguration
WithFrontend enables serving frontend
func WithMetrics ¶
func WithMetrics(uri ...string) ServerConfiguration
WithMetrics enables Prometheus metrics
func WithMiddleware ¶
func WithMiddleware(middleware ...func(http.Handler) http.Handler) ServerConfiguration
WithMiddleware enables additional middleware
func WithOpenAPI ¶
func WithOpenAPI(title, desc, version string) ServerConfiguration
WithOpenAPI enables OAS and sets title, description and version
func WithReflector ¶
func WithReflector(ref *openapi3.Reflector) ServerConfiguration
WithReflector sets a custom openapi3.Reflector
func WithRequestLogging ¶
func WithRequestLogging() ServerConfiguration
WithRequestLogging enables request logger
func WithStripPrefixes ¶
func WithStripPrefixes(prefixes ...string) ServerConfiguration
WithStripPrefixes sets which prefixes should be stripped from components in OAS
type ServerOptions ¶
type ServerOptions struct { ID string Port int RequestLogging bool FrontendPath string FrontendFS *embed.FS }
ServerOptions ...
type Spec ¶
type Spec struct { Path string OriginalPath string PathPrefix string Method string Body interface{} Responses []*Response Parameters []*Parameter Tags []string Summary string Description string Op *openapi3.Operation Auth bool Validate bool AuthAPI bool }
Spec holds dao for creating an OpenAPI spec for a route
func (*Spec) FullRouterPath ¶
FullRouterPath returns url with prefix if present
type SpecOpt ¶
SpecOpt ...
func WithDescription ¶
WithDescription adss a description
func WithErrBadRequest ¶
WithErrBadRequest creates a bad request error response Opt
func WithErrNotFound ¶
WithErrNotFound creates a not found error response Opt
func WithForbidden ¶
WithForbidden creates a forbidden error response Opt
func WithInternalError ¶
WithInternalError creates an internal server error response Opt
func WithOriginalPath ¶
WithOriginalPath adds a path to the request
func WithParam ¶
func WithParam(loc ParamLocation, title string, paramType ...string) SpecOpt
WithParam appends a path parameter
func WithParams ¶
WithParams merges params to operation
func WithPathPrefix ¶
WithPathPrefix adds a prefix for the request
func WithResponse ¶
WithResponse appends a response
func WithUnauthorized ¶
WithUnauthorized creates an unauthorized error response Opt
type TelemetryOptions ¶
TelemetryOptions ...
type WellKnown ¶
type WellKnown struct { Issuer string `json:"issuer"` AuthorizationEndpoint string `json:"authorization_endpoint"` TokenEndpoint string `json:"token_endpoint"` IntrospectionEndpoint string `json:"introspection_endpoint"` UserinfoEndpoint string `json:"userinfo_endpoint"` EndSessionEndpoint string `json:"end_session_endpoint"` FrontchannelLogoutSessionSupported bool `json:"frontchannel_logout_session_supported"` FrontchannelLogoutSupported bool `json:"frontchannel_logout_supported"` JwksURI string `json:"jwks_uri"` CheckSessionIframe string `json:"check_session_iframe"` GrantTypesSupported []string `json:"grant_types_supported"` AcrValuesSupported []string `json:"acr_values_supported"` ResponseTypesSupported []string `json:"response_types_supported"` SubjectTypesSupported []string `json:"subject_types_supported"` IDTokenSigningAlgValuesSupported []string `json:"id_token_signing_alg_values_supported"` IDTokenEncryptionAlgValuesSupported []string `json:"id_token_encryption_alg_values_supported"` IDTokenEncryptionEncValuesSupported []string `json:"id_token_encryption_enc_values_supported"` UserinfoSigningAlgValuesSupported []string `json:"userinfo_signing_alg_values_supported"` UserinfoEncryptionAlgValuesSupported []string `json:"userinfo_encryption_alg_values_supported"` UserinfoEncryptionEncValuesSupported []string `json:"userinfo_encryption_enc_values_supported"` RequestObjectSigningAlgValuesSupported []string `json:"request_object_signing_alg_values_supported"` RequestObjectEncryptionAlgValuesSupported []string `json:"request_object_encryption_alg_values_supported"` RequestObjectEncryptionEncValuesSupported []string `json:"request_object_encryption_enc_values_supported"` ResponseModesSupported []string `json:"response_modes_supported"` RegistrationEndpoint string `json:"registration_endpoint"` TokenEndpointAuthMethodsSupported []string `json:"token_endpoint_auth_methods_supported"` TokenEndpointAuthSigningAlgValuesSupported []string `json:"token_endpoint_auth_signing_alg_values_supported"` IntrospectionEndpointAuthMethodsSupported []string `json:"introspection_endpoint_auth_methods_supported"` IntrospectionEndpointAuthSigningAlgValuesSupported []string `json:"introspection_endpoint_auth_signing_alg_values_supported"` AuthorizationSigningAlgValuesSupported []string `json:"authorization_signing_alg_values_supported"` AuthorizationEncryptionAlgValuesSupported []string `json:"authorization_encryption_alg_values_supported"` AuthorizationEncryptionEncValuesSupported []string `json:"authorization_encryption_enc_values_supported"` ClaimsSupported []string `json:"claims_supported"` ClaimTypesSupported []string `json:"claim_types_supported"` ClaimsParameterSupported bool `json:"claims_parameter_supported"` ScopesSupported []string `json:"scopes_supported"` RequestParameterSupported bool `json:"request_parameter_supported"` RequestURIParameterSupported bool `json:"request_uri_parameter_supported"` RequireRequestURIRegistration bool `json:"require_request_uri_registration"` CodeChallengeMethodsSupported []string `json:"code_challenge_methods_supported"` TLSClientCertificateBoundAccessTokens bool `json:"tls_client_certificate_bound_access_tokens"` RevocationEndpoint string `json:"revocation_endpoint"` RevocationEndpointAuthMethodsSupported []string `json:"revocation_endpoint_auth_methods_supported"` RevocationEndpointAuthSigningAlgValuesSupported []string `json:"revocation_endpoint_auth_signing_alg_values_supported"` BackchannelLogoutSupported bool `json:"backchannel_logout_supported"` BackchannelLogoutSessionSupported bool `json:"backchannel_logout_session_supported"` DeviceAuthorizationEndpoint string `json:"device_authorization_endpoint"` BackchannelTokenDeliveryModesSupported []string `json:"backchannel_token_delivery_modes_supported"` BackchannelAuthenticationEndpoint string `json:"backchannel_authentication_endpoint"` BackchannelAuthenticationRequestSigningAlgValuesSupported []string `json:"backchannel_authentication_request_signing_alg_values_supported"` RequirePushedAuthorizationRequests bool `json:"require_pushed_authorization_requests"` PushedAuthorizationRequestEndpoint string `json:"pushed_authorization_request_endpoint"` MtlsEndpointAliases struct { TokenEndpoint string `json:"token_endpoint"` RevocationEndpoint string `json:"revocation_endpoint"` IntrospectionEndpoint string `json:"introspection_endpoint"` DeviceAuthorizationEndpoint string `json:"device_authorization_endpoint"` RegistrationEndpoint string `json:"registration_endpoint"` UserinfoEndpoint string `json:"userinfo_endpoint"` PushedAuthorizationRequestEndpoint string `json:"pushed_authorization_request_endpoint"` BackchannelAuthenticationEndpoint string `json:"backchannel_authentication_endpoint"` } `json:"mtls_endpoint_aliases"` }
WellKnown ...