Documentation ¶
Index ¶
- Variables
- func GetApiKey(r *http.Request, paramName string, pathIndex int) (string, bool)
- func GetApiKeyFromContext(ctx context.Context) (string, bool)
- func GetIPAddress(r *http.Request) string
- func GetRealIPFromContext(ctx context.Context) (string, bool)
- func Hook(handler http.Handler, middlewares ...Middleware) http.Handler
- func RealIP(next http.Handler) http.Handler
- type ApiKeyOption
- type CtxKey
- type Middleware
Constants ¶
This section is empty.
Variables ¶
View Source
var CtxKeyApiKey = CtxKey("X-API-Key")
View Source
var CtxKeyRealIP = CtxKey("X-Real-IP")
Functions ¶
func GetApiKey ¶
GetApiKey returns the client API key from the specified `url`. If `paramName`specified, parse from query. Otherwise, parse from URL path with specified `pathIndex`. Note, the `paramName` is case sensitive.
func GetApiKeyFromContext ¶
GetApiKeyFromContext get client API key from the specified `ctx`.
func GetIPAddress ¶
GetIPAddress returns the real remote IP address.
func GetRealIPFromContext ¶
GetRealIPFromContext get real remote IP address from the specified `ctx`.
Types ¶
type ApiKeyOption ¶
type CtxKey ¶
type CtxKey string
CtxKey is the key type for injected kv pair in the context of HTTP request.
type Middleware ¶
Middleware decorates HTTP Handler to response HTTP request.
func NewApiKeyMiddleware ¶
func NewApiKeyMiddleware(option ApiKeyOption) Middleware
NewApiKeyMiddleware creates middleware to inject client API key in context.
Click to show internal directories.
Click to hide internal directories.