Versions in this module Expand all Collapse all v1 v1.0.3 Jan 24, 2024 Changes in this version + func OverrideContextAuth[Ident any, ID comparable](parent context.Context, id ID, ident *Ident, roles []string) context.Context + func UseAuthContext[Ident any, ID comparable, Service AuthServiceReader[Ident, ID]](auth Service) func(next http.Handler) http.Handler + func UseAuthRequired[Ident any](next http.Handler) http.Handler + func UseRoleRequired[ID comparable](role string) func(http.Handler) http.Handler + type AuthServiceReader interface + Get func(context.Context, ID) (*Ident, error) + Roles func(context.Context, ID) ([]string, error) + type BasicAuthHandler struct + Auth BasicAuthService[Ident] + Ident *Ident + func NewBasicAuthHandler[Ident any](auth BasicAuthService[Ident], authKey, encryptKey string) *BasicAuthHandler[Ident] + func (h *BasicAuthHandler[Ident]) ServeHTTP(w http.ResponseWriter, r *http.Request) + func (h *BasicAuthHandler[Ident]) SetErrorHandler(handler ErrorHandler) + type BasicAuthService interface + BasicAuth func(context.Context, string, string) (*Ident, error) + Get func(context.Context, string) (*Ident, error) + Roles func(context.Context, string) ([]string, error) v1.0.2 Jan 10, 2024 v1.0.1 Nov 26, 2023 Changes in this version + var ErrAPIKeyInvalid = errors.New("invalid api key provided") + var ErrAPIKeyMissing = errors.New("api key not specified") + func RunContext(ctx context.Context, srv *http.Server, runners ...Runner) error + func RunTLS(srv *http.Server, certFile, keyFile string, runners ...Runner) error + func RunTLSContext(ctx context.Context, srv *http.Server, certFile, keyFile string, ...) error + func UseAPIVersionMatch(version string) func(next http.Handler) http.Handler + func UseRecoverer(next http.Handler) http.Handler type Runner + func RunnerInterval(name string, r Runner, frequency time.Duration, ...) Runner v1.0.0 Apr 24, 2023 Changes in this version + var DefaulltCookieMaxAge = 30 * 86400 + var DefaultAPIKeyHeader = "X-Api-Key" + var DefaultAPIPrefix = "/api/" + var DefaultAPIVersionHeader = "X-Api-Version" + var DefaultCookieSecure = false + var DefaultDecodeMaxMemory int64 = 8 << 20 + var DefaultDecoder = form.NewDecoder() + var DefaultMaskError = true + var DefaultValidator = validator.New() + var ErrAPIVersionMismatch = errors.New("server and client version mismatch") + var ErrAPIVersionMissing = errors.New("api version not specified") + var ErrAccessDenied = errors.New("access denied") + var ErrAuthMissingRole = errors.New("auth: missing necessary role") + var ErrAuthNotFound = errors.New("auth: no authentiation found") + var ErrInvalidAPIKey = errors.New("invalid api key provided") + var ErrNoAPIKeys = errors.New("no api keys provided") + var ErrRealIPNoOpts = errors.New("realip: no options specified") + var ErrRealIPNoSource = errors.New(...) + var ErrRealIPNoTrusted = errors.New("realip: no trusted proxies or bogon IPs specified") + var Error = defaultErrorHandler + func APIVersionMatch(version string) func(next http.Handler) http.Handler + func AddErrorResolver(r ErrorResolver) + func AddLogHandler(h LogHandler) + func Bind(r *http.Request, v any) (err error) + func ErrorCode(w http.ResponseWriter, r *http.Request, statusCode int, err error) bool + func GetContextIP(ctx context.Context) net.IP + func IDFromContext(ctx context.Context) (id ID) + func IdentFromContext(ctx context.Context) (auth *Ident) + func IsDebug(r *http.Request) bool + func IsDebugCtx(ctx context.Context) bool + func JSON(w http.ResponseWriter, r *http.Request, status int, v any) + func Log(r *http.Request) log.Interface + func Recoverer(next http.Handler) http.Handler + func Run(srv *http.Server, runners ...Runner) error + func RunCtx(ctx context.Context, srv *http.Server, runners ...Runner) error + func SecureRedirect(w http.ResponseWriter, r *http.Request, status int, fallback string) + func SkipNextURL(r *http.Request) *http.Request + func UnwrapError(err error) (error, int) + func UseAPIKeyRequired(keys []string) func(next http.Handler) http.Handler + func UseContextIP(next http.Handler) http.Handler + func UseDebug(debug bool) func(next http.Handler) http.Handler + func UseHeaders(headers map[string]string) func(next http.Handler) http.Handler + func UseIf(cond bool, handler func(http.Handler) http.Handler) func(http.Handler) http.Handler + func UseNextURL(next http.Handler) http.Handler + func UsePrivateIP(next http.Handler) http.Handler + func UsePrometheus(next http.Handler) http.Handler + func UseRealIP(trusted []string, flags RealIPOptions) func(next http.Handler) http.Handler + func UseRealIPCLIOpts(options []string) func(next http.Handler) http.Handler + func UseRealIPDefault(next http.Handler) http.Handler + func UseRobotsTxt(custom string) func(next http.Handler) http.Handler + func UseSecurityTxt(config *SecurityConfig) func(next http.Handler) http.Handler + func UseStatic(ctx context.Context, config *Static) http.Handler + func UseStructuredLogger(logger log.Interface) func(next http.Handler) http.Handler + func WrapCode(code int) error + func WrapError(err error, code int) error + type AuthHandler struct + Auth AuthService[Ident, ID] + ID *ID + Ident *Ident + func NewAuthHandler(auth AuthService[Ident, ID], authKey, encryptKey string) *AuthHandler[Ident, ID] + func (h *AuthHandler[Ident, ID]) AddToContext(next http.Handler) http.Handler + func (h *AuthHandler[Ident, ID]) AuthRequired(next http.Handler) http.Handler + func (h *AuthHandler[Ident, ID]) FromContext(ctx context.Context) (auth *Ident) + func (h *AuthHandler[Ident, ID]) RoleRequired(role string) func(http.Handler) http.Handler + func (h *AuthHandler[Ident, ID]) RolesFromContext(ctx context.Context) (roles AuthRoles) + func (h *AuthHandler[Ident, ID]) ServeHTTP(w http.ResponseWriter, r *http.Request) + func (h *AuthHandler[Ident, ID]) SetErrorHandler(handler ErrorHandler) + type AuthRoles []string + func RolesFromContext(ctx context.Context) (roles AuthRoles) + func (r AuthRoles) Has(role string) bool + type AuthService interface + Get func(context.Context, ID) (*Ident, error) + Roles func(context.Context, ID) ([]string, error) + Set func(context.Context, *goth.User) (ID, error) + type ErrRealIPInvalidIP struct + Err error + func (e ErrRealIPInvalidIP) Error() string + func (e ErrRealIPInvalidIP) Unwrap() error + type ErrWithStatusCode struct + Code int + Err error + func (e ErrWithStatusCode) Error() string + func (e ErrWithStatusCode) Unwrap() error + type ErrorHandler func(w http.ResponseWriter, r *http.Request, err error) (ok bool) + type ErrorResolver func(err error) (status int) + type LogHandler func(r *http.Request) M + type M map[string]any + func (m M) Fields() (f log.Fields) + type RealIPOptions int + const OptDefaultTrust + const OptTrustAny + const OptTrustBogon + const OptTrustCloudflare + const OptUseCFConnectingIP + const OptUseTrueClientIP + const OptUseXForwardedFor + const OptUseXRealIP + type Runner func(ctx context.Context) error + func (r Runner) Invoke(ctx context.Context) func() error + type SecurityConfig struct + Acknowledgements []string + Canonical []string + Contacts []string + Expires time.Time + ExpiresIn time.Duration + KeyLinks []string + Languages []string + Policies []string + func (h *SecurityConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) + type Static struct + AllowLocal bool + CatchAll bool + FS fs.FS + Headers map[string]string + LocalPath string + Path string + Prefix string + SPA bool + func (s *Static) ServeHTTP(w http.ResponseWriter, r *http.Request) + type Validatable interface + Validate func() error