requestid

package
v0.0.0-...-d6b3ade Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultGenerator = Generator{
	Prefix: HostnamePrefix(),
}

DefaultGenerator is the default ID generator, using the hostname and some random bytes as its prefix.

Functions

func Get

func Get(ctx context.Context) string

Get wraps DefaultGenerator.Get.

func HostnamePrefix

func HostnamePrefix() string

HostnamePrefix returns a prefix based on the system's hostname, of the format:

<hostname>/<10 random bytes>

func Next

func Next(r *http.Request) string

Next wraps DefaultGenerator.Next.

func RandomPrefix

func RandomPrefix(len int) string

RandomPrefix returns a random prefix, a hexadecimal string of length len.

func Set

func Set(parent context.Context, id string) context.Context

Set wraps DefaultGenerator.Set.

Types

type Generator

type Generator struct {
	Prefix string
	// contains filtered or unexported fields
}

Generator generates request IDs with the set prefix.

func (*Generator) Get

func (c *Generator) Get(ctx context.Context) string

Get attempts to get the current request ID from the provided context.Context. It'll return an empty string if the context doesn't contain a request ID.

func (*Generator) Next

func (c *Generator) Next(r *http.Request) string

Next checks the passed request for an incoming request ID; if its set, that's the request ID we use. Otherwise, we'll generate the next request ID and return it.

func (*Generator) Set

func (c *Generator) Set(parent context.Context, id string) context.Context

Set returns a copy of the provided context.Context with the provided request ID as a value.

Jump to

Keyboard shortcuts

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