ctxkit

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get[T any](ctx context.Context, key Key) T

Get gets value of type T from context. If valued does not exist returns zeroed value for type T.

func GetLogErrHook

func GetLogErrHook(ctx context.Context) func(error)

GetLogErrHook gets the hook function from the context which sets the error to server error log. If searched values is absent in context, then nil wil be returned.

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID gets the request ID from the context. If searched values is absent in context, then empty string wil be returned.

func Set

func Set[T any](ctx context.Context, key Key, value T) context.Context

Set sets given value T to the context by given Key.

func SetLogErrHook

func SetLogErrHook(ctx context.Context, hook func(err error)) context.Context

SetLogErrHook sets the hook function to the context.

func SetRequestID

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

SetRequestID sets the request ID to the context.

Types

type Key

type Key string

Key represents a context Key with custom type.

Jump to

Keyboard shortcuts

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