middlewares

package
v0.0.0-...-69d59ad Latest Latest
Warning

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

Go to latest
Published: May 10, 2025 License: MIT, MIT, MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClientPlatformIOS     = "ios"
	ClientPlatformAndroid = "android"
)

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(next http.Handler) http.Handler

ClientIP overrides the RemoteAddr field of the request with data from the relevant headers, if present.

func GetOrSetRequestID

func GetOrSetRequestID(ctx context.Context) (context.Context, string)

GetOrSetRequestID will return any request ID found in the context, and if one does not exist, set and return.

func GetRequestID

func GetRequestID(r *http.Request) string

GetRequestID returns the request id embedded within a HTTP request's context, or an empty string if no request id has been established.

func HealthCheck

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

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 RequestID

func RequestID(next http.Handler) http.Handler

RequestID either generates a new request id or acquires an existing request id from the http requests headers, and embeds into the requests context and response headers.

func SetRequestID

func SetRequestID(r *http.Request, requestID string) *http.Request

SetRequestID sets the request id within a HTTP requests's context, it will overwrite any existing request id.

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.

func Telemetry

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

Telemetry 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 UnsafeNoAuthentication

func UnsafeNoAuthentication(next crpc.HandlerFunc) crpc.HandlerFunc

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