Documentation
¶
Overview ¶
Package webservice exposes a small HTTP service scaffold.
Index ¶
- Constants
- func AuthWithValidator(_ *redis.Client, basePath string, spec *openapi3.T, ...) echo.MiddlewareFunc
- func CorrelationContextEnricher(baseLogger *zerolog.Logger) echo.MiddlewareFunc
- func RateLimiter(rdb *redis.Client, maxRequests int, duration time.Duration) echo.MiddlewareFunc
- func RequestLogger(baseLogger *zerolog.Logger) echo.MiddlewareFunc
- func RoleValidator(spec *openapi3.T) echo.MiddlewareFunc
- func SetCorrelationID() echo.MiddlewareFunc
- func SourceIP() echo.MiddlewareFunc
- func TracingMiddleware(next echo.HandlerFunc) echo.HandlerFunc
- type APIBuilder
- func (b *APIBuilder) AddFilesystemPath(urlPath string, filesystemPath string) *APIBuilder
- func (b *APIBuilder) AddServerIf(condition bool, server string) *APIBuilder
- func (b *APIBuilder) AllowHeaders(headers ...string) *APIBuilder
- func (b *APIBuilder) AllowMethods(methods ...string) *APIBuilder
- func (b *APIBuilder) AllowOrigins(origins ...string) *APIBuilder
- func (b *APIBuilder) ClearServers() *APIBuilder
- func (b *APIBuilder) CustomAPITokenValidation(f CustomApiAuthentication) *APIBuilder
- func (b *APIBuilder) CustomGET(path string, handler echo.HandlerFunc) *APIBuilder
- func (b *APIBuilder) EmbedFS(path string, webFs embed.FS) *APIBuilder
- func (b *APIBuilder) EnablePrometheus(enable bool) *APIBuilder
- func (b *APIBuilder) EnableSwagger(enable bool) *APIBuilder
- func (b *APIBuilder) ErrorHandler(f CustomErrorHandler) *APIBuilder
- func (b *APIBuilder) OnEveryCall(handler echo.MiddlewareFunc) *APIBuilder
- func (b *APIBuilder) PublicAPI(basePath string, oapiSpecificationPath string, publicName string) *APIBuilder
- func (b *APIBuilder) RegisterHandler(handler func(*echo.Echo)) *APIBuilder
- func (b *APIBuilder) Run(listenPort int) error
- func (b *APIBuilder) RunHttps(listenPort int, certFile interface{}, keyFile interface{}) error
- func (b *APIBuilder) SetApplicationName(appName string) *APIBuilder
- func (b *APIBuilder) ThrottleRequests(threshold int, window time.Duration) *APIBuilder
- func (b *APIBuilder) UseOpenAPISpecs(basePath string, oapiSpecificationPath string, publicName string) *APIBuilder
- func (b *APIBuilder) UseRedisCache(redisClient *redis.Client) *APIBuilder
- func (b *APIBuilder) WithAuthentication(oidcBaseURL string, loginOIDCBaseURL string) *APIBuilder
- func (b *APIBuilder) WithLogger(logger zerolog.Logger) *APIBuilder
- func (b *APIBuilder) WithOpenTelemetry() *APIBuilder
- func (b *APIBuilder) WithRoleValidation(enable bool) *APIBuilder
- type APIDescriptor
- type CustomApiAuthentication
- type CustomErrorHandler
- type MergePatchBinder
- type OapiRegisterFunc
Constants ¶
const ( ContextKey_UserID = "userid" ContextKey_UserEmail = "email" ContextKey_GivenName = "given_name" ContextKey_FamilyName = "family_name" ContextKey_EmailVerified = "email_verified" ContextKey_Roles = "roles" ContextKey_SourceIP = "source_ip" ContextKey_Correlation = "correlation_id" )
Variables ¶
This section is empty.
Functions ¶
func AuthWithValidator ¶
func AuthWithValidator(_ *redis.Client, basePath string, spec *openapi3.T, oidcBaseURL, loginOIDCBaseURL *string, customAPITokenChecker CustomApiAuthentication) echo.MiddlewareFunc
This middleware validates the request against the OpenAPI spec and also checks the Authorization header for a valid JWT token
func CorrelationContextEnricher ¶
func CorrelationContextEnricher(baseLogger *zerolog.Logger) echo.MiddlewareFunc
func RateLimiter ¶
Request limiter will limit the number of requests from a single IP address
As single instance redis is not required as the stats are in-memory On multiple instances with a loadbalancer, a distributed cache like redis is required
func RequestLogger ¶
func RequestLogger(baseLogger *zerolog.Logger) echo.MiddlewareFunc
func RoleValidator ¶
func RoleValidator(spec *openapi3.T) echo.MiddlewareFunc
func SetCorrelationID ¶
func SetCorrelationID() echo.MiddlewareFunc
SetCorrelationID provides a middleware that ensures every response carries an X-CORRELATION-ID header. Precedence: CF-RAY > X-CORRELATION-ID > generated.
func SourceIP ¶
func SourceIP() echo.MiddlewareFunc
func TracingMiddleware ¶
func TracingMiddleware(next echo.HandlerFunc) echo.HandlerFunc
Types ¶
type APIBuilder ¶
type APIBuilder struct {
// contains filtered or unexported fields
}
func NewWebServer ¶
func NewWebServer(appName string) *APIBuilder
func (*APIBuilder) AddFilesystemPath ¶ added in v0.9.2
func (b *APIBuilder) AddFilesystemPath(urlPath string, filesystemPath string) *APIBuilder
AddFilesystem adds a filesystem to be served at the given URL path
func (*APIBuilder) AddServerIf ¶
func (b *APIBuilder) AddServerIf(condition bool, server string) *APIBuilder
Add a server URL if the condition is true
func (*APIBuilder) AllowHeaders ¶
func (b *APIBuilder) AllowHeaders(headers ...string) *APIBuilder
func (*APIBuilder) AllowMethods ¶
func (b *APIBuilder) AllowMethods(methods ...string) *APIBuilder
func (*APIBuilder) AllowOrigins ¶
func (b *APIBuilder) AllowOrigins(origins ...string) *APIBuilder
AllowOrigins sets the allowed origins for CORS
func (*APIBuilder) ClearServers ¶
func (b *APIBuilder) ClearServers() *APIBuilder
func (*APIBuilder) CustomAPITokenValidation ¶
func (b *APIBuilder) CustomAPITokenValidation(f CustomApiAuthentication) *APIBuilder
func (*APIBuilder) CustomGET ¶
func (b *APIBuilder) CustomGET(path string, handler echo.HandlerFunc) *APIBuilder
func (*APIBuilder) EmbedFS ¶ added in v0.9.2
func (b *APIBuilder) EmbedFS(path string, webFs embed.FS) *APIBuilder
func (*APIBuilder) EnablePrometheus ¶
func (b *APIBuilder) EnablePrometheus(enable bool) *APIBuilder
func (*APIBuilder) EnableSwagger ¶
func (b *APIBuilder) EnableSwagger(enable bool) *APIBuilder
func (*APIBuilder) ErrorHandler ¶
func (b *APIBuilder) ErrorHandler(f CustomErrorHandler) *APIBuilder
func (*APIBuilder) OnEveryCall ¶
func (b *APIBuilder) OnEveryCall(handler echo.MiddlewareFunc) *APIBuilder
Add some Echo Middleware to be executed on every call
func (*APIBuilder) PublicAPI ¶
func (b *APIBuilder) PublicAPI(basePath string, oapiSpecificationPath string, publicName string) *APIBuilder
func (*APIBuilder) RegisterHandler ¶
func (b *APIBuilder) RegisterHandler(handler func(*echo.Echo)) *APIBuilder
func (*APIBuilder) Run ¶
func (b *APIBuilder) Run(listenPort int) error
func (*APIBuilder) RunHttps ¶ added in v0.9.2
func (b *APIBuilder) RunHttps(listenPort int, certFile interface{}, keyFile interface{}) error
Run with TLS using local certificate and key files
func (*APIBuilder) SetApplicationName ¶
func (b *APIBuilder) SetApplicationName(appName string) *APIBuilder
func (*APIBuilder) ThrottleRequests ¶
func (b *APIBuilder) ThrottleRequests(threshold int, window time.Duration) *APIBuilder
ThrottleRequests enables request throttling with the given threshold and window
func (*APIBuilder) UseOpenAPISpecs ¶
func (b *APIBuilder) UseOpenAPISpecs(basePath string, oapiSpecificationPath string, publicName string) *APIBuilder
func (*APIBuilder) UseRedisCache ¶
func (b *APIBuilder) UseRedisCache(redisClient *redis.Client) *APIBuilder
func (*APIBuilder) WithAuthentication ¶
func (b *APIBuilder) WithAuthentication(oidcBaseURL string, loginOIDCBaseURL string) *APIBuilder
WithAuthentication enables OIDC authentication with the given OIDC base URL
func (*APIBuilder) WithLogger ¶
func (b *APIBuilder) WithLogger(logger zerolog.Logger) *APIBuilder
func (*APIBuilder) WithOpenTelemetry ¶
func (b *APIBuilder) WithOpenTelemetry() *APIBuilder
-- if set a middleware will keep pushing metrics thru otel collector -- in order for this to work the collector needs to be initialized in main
func (*APIBuilder) WithRoleValidation ¶
func (b *APIBuilder) WithRoleValidation(enable bool) *APIBuilder
WithRoleValidation enables or disables role validation middleware Requires x-role annotations in OpenAPI spec
type APIDescriptor ¶
type APIDescriptor struct {
SpecPath string
Handler interface{}
}
-- Errors provided through the API