contextex

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrContextValuesNotFound    = errors.New("context values not found")
	ErrContextValuesKeyNotFound = errors.New("key not found")
	ErrTypeConversion           = errors.New("invalid type conversion")
)

Functions

func CreateContextWithMap

func CreateContextWithMap(ctx context.Context, valuesKey ContextValuesKey, cm ContextMap) context.Context

func CreateContextWithValues

func CreateContextWithValues(ctx context.Context, valuesKey ContextValuesKey, values Values) context.Context

func GetContextValuesKey

func GetContextValuesKey(ctx context.Context, contextValuesKey ContextValuesKey, key ContextKey) (interface{}, error)

GetContextValuesKey get value for key from contextValuesKey map stored in context.

func GetFieldsMap

func GetFieldsMap(ctx context.Context, contextValuesKey ContextValuesKey,
	fields ...interface{}) (map[string]interface{}, error)

GetFieldsMap - get field list from Context and append fields list to it.

func WrapError

func WrapError(message string, err error) error

Types

type ContextKey

type ContextKey string

ContextKey comprises keys used to access common information from a request context.

type ContextMap

type ContextMap map[ContextKey]interface{}

ContextMap - Context Map type wrapped by Values.

func PairFields

func PairFields(fields ...interface{}) ContextMap

type ContextValuesKey

type ContextValuesKey string

ContextValuesKey - Context Values Key type.

type Values

type Values struct {
	// contains filtered or unexported fields
}

Values - struct to store values on context.

func GetContextValues

func GetContextValues(ctx context.Context, contextValuesKey ContextValuesKey) (*Values, error)

GetContextValues contextValuesKey map stored in context.

func NewValues

func NewValues(m ContextMap) Values

func (Values) GetKey

func (v Values) GetKey(key ContextKey) interface{}

GetKey - GetKey value from Values struct.

func (Values) GetMap

func (v Values) GetMap() ContextMap

GetMap - GetMap value from Values struct.

Jump to

Keyboard shortcuts

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