hcontext

package
v0.0.36 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: BSD-3-Clause Imports: 4 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 from the Headers. If one is found, it appends a new request ID and sets the comma separated value as the header. If one is not found, it sets a new request ID as the header.

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
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.

Jump to

Keyboard shortcuts

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