Documentation
¶
Index ¶
- Constants
- func ClientIP(next http.Handler) http.Handler
- func GetOrSetRequestID(ctx context.Context) (context.Context, string)
- func GetRequestID(r *http.Request) string
- func HealthCheck(w http.ResponseWriter, _ *http.Request)
- func ParseClientVersion(next http.Handler) http.Handler
- func RequestID(next http.Handler) http.Handler
- func SetRequestID(r *http.Request, requestID string) *http.Request
- func StripPrefix(prefix string) func(http.Handler) http.Handler
- func Telemetry(log *logrus.Entry) func(http.Handler) http.Handler
- func UnsafeNoAuthentication(next crpc.HandlerFunc) crpc.HandlerFunc
- type ClientVersion
Constants ¶
const ( ClientPlatformIOS = "ios" ClientPlatformAndroid = "android" )
Variables ¶
This section is empty.
Functions ¶
func ClientIP ¶
ClientIP overrides the RemoteAddr field of the request with data from the relevant headers, if present.
func GetOrSetRequestID ¶
GetOrSetRequestID will return any request ID found in the context, and if one does not exist, set and return.
func GetRequestID ¶
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 ¶
ParseClientVersion attempts to parse the infra-client-version HTTP header and add it as a struct to the context
func RequestID ¶
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 ¶
SetRequestID sets the request id within a HTTP requests's context, it will overwrite any existing request id.
func StripPrefix ¶
StripPrefix is HTTP Middleware that will strip a prefix from a URL before hitting an endpoint.
func Telemetry ¶
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 ¶
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