Documentation ¶
Index ¶
- Constants
- Variables
- func AddToContext(r *http.Request, key, val interface{})
- func BasicAuth(next http.Handler, username, password string) http.HandlerFunc
- func ExtractJSON(r *http.Request, to interface{}) error
- func ExtractQuery(r *http.Request, to interface{}) error
- func JSONResponse(w http.ResponseWriter, response interface{}, code int)
- func MakeLoggingMiddleware(logger *log.Logger) func(next http.Handler) http.Handler
- func NonAuthJWT(next http.HandlerFunc, auth auth) http.HandlerFunc
- func ParseBearerToken(r *http.Request) (string, error)
- type ContextKey
- type RequestInfo
Constants ¶
View Source
const ( AuthorizationHeader = "Authorization" UserAgentHeader = "User-Agent" RealIPHeader = "X-Real-Ip" XForwardedForHeader = "x-forwarded-for" RefererHeader = "Referer" Bearer = "Bearer" RequestInfoKey ContextKey = "requestInfo" ContextKeyUserID ContextKey = "userID" AccessTokenKey ContextKey = "accessToken" )
Variables ¶
View Source
var (
ErrUserAgentIsMissing = errors.New("user-agent is missing from header")
)
Functions ¶
func AddToContext ¶
func BasicAuth ¶
func BasicAuth(next http.Handler, username, password string) http.HandlerFunc
BasicAuth protects endpoint with basic authentication
func ExtractJSON ¶
func ExtractQuery ¶
func JSONResponse ¶
func JSONResponse(w http.ResponseWriter, response interface{}, code int)
func MakeLoggingMiddleware ¶
MakeLoggingMiddleware creates request logging middleware
func NonAuthJWT ¶
func NonAuthJWT(next http.HandlerFunc, auth auth) http.HandlerFunc
NonAuthJWT is a middleware for microservices that want to contact auth microservice to validate token. Will add user id in context using key ContextKeyUserID
Types ¶
type ContextKey ¶
type ContextKey string
type RequestInfo ¶
type RequestInfo struct { Method string Referer string XForwardedFor string UserAgent string IPAddr string Code int Size int64 Duration time.Duration }
func GetRequestInfo ¶
func GetRequestInfo(r *http.Request) *RequestInfo
func NewRequestInfo ¶
func NewRequestInfo(r *http.Request) *RequestInfo
Click to show internal directories.
Click to hide internal directories.