kv

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2021 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package kv provides a way to work with keys and values. Those let keep the consistency among packages when working with key-value pairs. Functionality for some pre-defined context attributes is also provided.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecorateWithAttributes added in v2.4.0

func DecorateWithAttributes(inUse, background context.Context) context.Context

DecorateWithAttributes adds the static attributes as values in the resulting context.

func SetDynamicAttributes added in v2.4.0

func SetDynamicAttributes(
	ctx context.Context,
	correlationID string,
	isDryRun bool,
) context.Context

SetDynamicAttributes sets request attributes (correlation ID and the is dry run) into the given context.

func SetStaticAttributes added in v2.4.0

func SetStaticAttributes(
	ctx context.Context,
	buildID, serviceHost, serviceName string,
) context.Context

SetStaticAttributes sets program attributes (build ID, service host and service name) into the given context.

Types

type Pair

type Pair struct {
	Val
	// contains filtered or unexported fields
}

Pair encapsulates a key-value representation. All Val methods can be accessed from a Pair.

func AllAttributes added in v2.4.0

func AllAttributes(ctx context.Context) []Pair

AllAttributes returns all the known pairs that exist in the context.

func CorrelationID

func CorrelationID(ctx context.Context) Pair

CorrelationID returns pair holding that information from the given context.

func IsDryRun

func IsDryRun(ctx context.Context) Pair

IsDryRun returns pair holding that information from the given context.

func New

func New(key string, val interface{}) Pair

New generates a new Pair using the given key and values.

func NewObfuscated

func NewObfuscated(key string, val interface{}) Pair

NewObfuscated generates a new Pair using the given key. The value, however, will be obfuscated. This prevents situations where a value is not supposed to be reported to other components. Only strings are supported at this time.

func (Pair) Name

func (p Pair) Name() string

Name returns the key name of the Pair.

type Val

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

Val encapsulates the given value. Keeping it encapsulated allows to work with obfuscated pairs. A value can also be used on its own.

func Value

func Value(v interface{}) Val

Value returns a new value to be used outside any Pair.

func (Val) Bool

func (v Val) Bool() bool

Bool returns the raw boolean value, or false if one doesn't exist.

func (Val) Int

func (v Val) Int() int

Int returns the raw integer value, or 0 if one doesn't exist.

func (Val) String

func (v Val) String() string

String returns the raw string value, or empty string if one doesn't exist. If the value is obfuscated, a redacted value is provided instead.

func (Val) Value

func (v Val) Value() interface{}

Value returns the raw value in its original form. If the value is obfuscated, a redacted value is provided instead.

Jump to

Keyboard shortcuts

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