httpx

package
v0.0.0-...-1762b78 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

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 AddToContext(r *http.Request, key, val interface{})

func BasicAuth

func BasicAuth(next http.Handler, username, password string) http.HandlerFunc

BasicAuth protects endpoint with basic authentication

func ExtractJSON

func ExtractJSON(r *http.Request, to interface{}) error

func ExtractQuery

func ExtractQuery(r *http.Request, to interface{}) error

func JSONResponse

func JSONResponse(w http.ResponseWriter, response interface{}, code int)

func MakeLoggingMiddleware

func MakeLoggingMiddleware(logger *log.Logger) func(next http.Handler) http.Handler

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

func ParseBearerToken

func ParseBearerToken(r *http.Request) (string, error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL