Documentation ¶
Overview ¶
Package hcontext is a small set of helpers and utilities for managing values commonly kept in contexts in Heroku Go code.
Each additional bit of data stored in a context should have its own files in this package.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromRequest ¶
FromRequest fetches the given request's request ID if it has one, and returns a new random request ID if it does not.
Example ¶
var r http.Request reqID, ok := FromRequest(&r) if !ok { log.Printf("when handling request from %s, no request ID", r.RemoteAddr) return } log.Printf("The request ID is: %s", reqID)
Output:
func RequestIDFromContext ¶
RequestIDFromContext fetches a request ID from the given context if it exists.
func WithRequestID ¶
WithRequestID adds the given request ID to a context for processing later down the chain.
Example ¶
r := &http.Request{} reqID, ok := FromRequest(r) if !ok { log.Printf("when handling request from %s, no request ID", r.RemoteAddr) return } ctx := WithRequestID(r.Context(), reqID) r = r.WithContext(ctx) _ = r
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.