contextx

package
v0.0.385 Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: Apache-2.0 Imports: 3 Imported by: 17

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNoConfigInContext = errors.New("configuration provider not found in context")

ErrNoConfigInContext is returned when no config is found in the context.

Functions

func ConfigFromContext

func ConfigFromContext(ctx context.Context) (*configx.Provider, error)

ConfigFromContext returns the configuration provider from the context or an error if no configuration provider is found in the context.

Example
ctx := context.Background()

config, err := configx.New(ctx, []byte(`{"type":"object","properties":{"foo":{"type":"string"}}}`), configx.WithValue("foo", "bar"))
if err != nil {
	panic(err)
}

ctx = WithConfig(ctx, config)
fmt.Printf("foo = %s", MustConfigFromContext(ctx).String("foo"))
Output:

foo = bar

func IsRootContext

func IsRootContext(ctx context.Context) bool

func MustConfigFromContext

func MustConfigFromContext(ctx context.Context) *configx.Provider

MustConfigFromContext returns the configuration provider from the context or panics if no configuration provider is found in the context.

func WithConfig

func WithConfig(ctx context.Context, p *configx.Provider) context.Context

WithConfig returns a new context with the given configuration provider.

Types

type ContextKey

type ContextKey int
const (
	ValidContextKey ContextKey = iota + 1
)

Jump to

Keyboard shortcuts

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