Documentation ¶
Index ¶
- Constants
- func Apply(h http.Handler) http.Handler
- func CORSWithOptions(options *CORSOptions) func(http.Handler) http.Handler
- func GetLogEntryMetadata(ctx context.Context) map[string]interface{}
- func LoggerWithOptions(options *LoggerOptions) func(http.Handler) http.Handler
- func Postgres(pool *pgxpool.Pool, authorizers ...AuthzFunc) func(http.Handler) http.Handler
- func Proxy(target string, opts Options) http.HandlerFunc
- func Register(middlewares ...Middleware)
- func RequestID(next http.Handler) http.Handler
- func VerifyBasicAuth(config *BasicAuthConfig) func(http.Handler) http.Handler
- func VerifyOIDCToken(oidcCfg OIDCProviderConfig, send401Unauthorized ...bool) func(http.Handler) http.Handler
- type AuthzFunc
- type AuthzResponse
- type BasicAuthConfig
- type CORSOptions
- type Cache
- type LoggerOptions
- type Middleware
- type OIDCProvider
- type OIDCProviderConfig
- type Options
- type ResponseRecorder
Constants ¶
const RequestIDHeader = "X-Request-Id"
Variables ¶
This section is empty.
Functions ¶
func CORSWithOptions ¶
func CORSWithOptions(options *CORSOptions) func(http.Handler) http.Handler
CORSWithOptions creates a CORS middleware with the provided configuration. If options is nil, it will use the default CORS settings. If options is an empty struct (CORSOptions{}), it will create a middleware with no CORS headers.
func GetLogEntryMetadata ¶
Retrieve log metadata from context
func LoggerWithOptions ¶
func LoggerWithOptions(options *LoggerOptions) func(http.Handler) http.Handler
func Postgres ¶
Postgres middleware attaches a connection from pool to the request context if the http request user is authorized.
func Proxy ¶
func Proxy(target string, opts Options) http.HandlerFunc
Serve creates a reverse proxy handler based on the given target and options
func Register ¶
func Register(middlewares ...Middleware)
Register adds one or more middleware function to the registry.
func VerifyBasicAuth ¶
func VerifyBasicAuth(config *BasicAuthConfig) func(http.Handler) http.Handler
VerifyBasicAuth is a middleware function for basic authentication.
func VerifyOIDCToken ¶
func VerifyOIDCToken(oidcCfg OIDCProviderConfig, send401Unauthorized ...bool) func(http.Handler) http.Handler
VerifyOIDCToken is middleware that verifies OIDC tokens in Authorization headers. By default, it sends a 401 Unauthorized response if the token is missing or invalid. If send401Unauthorized is false, it allows requests with other authorization schemes (e.g., Basic Auth) to continue without interference.
Types ¶
type AuthzFunc ¶
type AuthzFunc func(ctx context.Context) (AuthzResponse, error)
AuthzFunc defines the function signature for authorization checks
func PgAnonAuthz ¶
func PgAnonAuthz() AuthzFunc
WithAnonAuthz returns an authorization function for anonymous users
func PgBasicAuthz ¶
func PgBasicAuthz() AuthzFunc
WithBasicAuthz returns an authorization function for Basic Auth
func PgOIDCAuthz ¶
func PgOIDCAuthz(oidcCfg OIDCProviderConfig, pgRoleClaimKey string) AuthzFunc
PgOIDCAuthz is the main authorization function
type AuthzResponse ¶
AuthzResponse represents the result of an authorization check
type BasicAuthConfig ¶
BasicAuthConfig holds the username-password pairs for basic authentication.
func BasicAuthCreds ¶
func BasicAuthCreds(credentials map[string]string) *BasicAuthConfig
NewBasicAuthCreds creates a new instance of BasicAuthConfig with multiple username/password pairs.
type CORSOptions ¶
type CORSOptions struct { AllowedOrigins []string AllowedMethods []string AllowedHeaders []string AllowCredentials bool }
CORSOptions defines configuration for CORS.
type Cache ¶
Cache is a simple in-memory cache with expiration
func (*Cache) CleanupExpired ¶
func (c *Cache) CleanupExpired()
CleanupExpired removes expired items from the cache
type LoggerOptions ¶
type LoggerOptions struct { Logger *zap.Logger Format func(reqID string, rec *ResponseRecorder, r *http.Request, latency time.Duration) []zap.Field }
LoggerOptions defines configuration for the logger middleware.
type Middleware ¶
Middleware is a function that wraps an HTTP handler.
type OIDCProvider ¶
type OIDCProvider struct {
// contains filtered or unexported fields
}
OIDCProvider is the main OIDC provider
func InitOIDCProvider ¶
func InitOIDCProvider(cfg OIDCProviderConfig) *OIDCProvider
type OIDCProviderConfig ¶
type OIDCProviderConfig struct { ClientID string `json:"client_id"` ClientSecret string `json:"client_secret"` Issuer string `json:"issuer"` }
OIDCProviderConfig holds the configuration for the OIDC provider
type ResponseRecorder ¶
type ResponseRecorder struct { http.ResponseWriter StatusCode int // contains filtered or unexported fields }
ResponseRecorder is a wrapper for http.ResponseWriter to capture status codes and durations.
func NewResponseRecorder ¶
func NewResponseRecorder(w http.ResponseWriter) *ResponseRecorder
func (*ResponseRecorder) WriteHeader ¶
func (rr *ResponseRecorder) WriteHeader(statusCode int)