hcontext

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2019 License: BSD-3-Clause Imports: 3 Imported by: 0

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

func FromRequest(r *http.Request) (id string, ok bool)

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

func RequestIDFromContext(ctx context.Context) (id string, ok bool)

RequestIDFromContext fetches a request ID from the given context if it exists.

func WithRequestID

func WithRequestID(ctx context.Context, id string) context.Context

WithRequestID adds the given request ID to a context for processing later down the chain.

Example
var 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)
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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