request

package
v0.0.0-...-81f452b Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT, MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ClientPlatformIOS     = "ios"
	ClientPlatformAndroid = "android"
)
View Source
const ClientIPHeader = `Infra-Client-Ip`

ClientIPHeader is the customer header, set by our network edge, that is expected to be the clients real IP address when X-Forwarded-For cannot be trusted.

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(next http.Handler) http.Handler

ClientIP respects the infra-client-ip header containing the clients real IP address.

func HealthCheck

func HealthCheck(w http.ResponseWriter, _ *http.Request)

func Logger

func Logger(log *logrus.Entry) func(http.Handler) http.Handler

Logger returns a middleware handler that wraps subsequent middleware/handlers and logs request information AFTER the request has completed. It also injects a request-scoped logger on the context which can be set, read and updated using clog lib

Included fields:

  • Request ID (request_id)
  • HTTP Method (http_method)
  • HTTP Path (http_path)
  • HTTP Protocol Version (http_proto)
  • Remote Address (http_remote_addr)
  • User Agent Header (http_user_agent)
  • Referer Header (http_referer)
  • Duration with unit (http_duration)
  • Duration in microseconds (http_duration_us)
  • HTTP Status Code (http_status)
  • Response in bytes (http_response_bytes)
  • Client Version header (http_client_version)
  • User Agent header (http_user_agent)

func ParseClientVersion

func ParseClientVersion(next http.Handler) http.Handler

ParseClientVersion attempts to parse the infra-client-version HTTP header and add it as a struct to the context

func StripPrefix

func StripPrefix(prefix string) func(http.Handler) http.Handler

StripPrefix is HTTP Middleware that will strip a prefix from a URL before hitting an endpoint.

Types

type ClientVersion

type ClientVersion struct {
	Platform string
	Version  semver.Version
	Build    int
}

ClientVersion represents a parsed client version header string

func GetClientVersion

func GetClientVersion(r *http.Request) *ClientVersion

GetClientVersion retrieves the parsed version from a request

func GetClientVersionContext

func GetClientVersionContext(ctx context.Context) *ClientVersion

GetClientVersionContext retrieves the parsed version from a request context

Jump to

Keyboard shortcuts

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