contextx

package
v0.0.493 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2022 License: Apache-2.0 Imports: 4 Imported by: 14

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 SetNIDContext added in v0.0.387

func SetNIDContext(ctx context.Context, nid uuid.UUID) context.Context

SetNIDContext sets the nid for the given 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
)

type Contextualizer added in v0.0.387

type Contextualizer interface {
	// Network returns the network id for the given context.
	Network(ctx context.Context, network uuid.UUID) uuid.UUID

	// Config returns the config for the given context.
	Config(ctx context.Context, config *configx.Provider) *configx.Provider
}

type Default added in v0.0.387

type Default struct{}

func (*Default) Config added in v0.0.387

func (d *Default) Config(ctx context.Context, config *configx.Provider) *configx.Provider

func (*Default) Network added in v0.0.387

func (d *Default) Network(ctx context.Context, network uuid.UUID) uuid.UUID

type NoOp added in v0.0.458

type NoOp struct{}

func (*NoOp) Config added in v0.0.458

func (d *NoOp) Config(ctx context.Context, config *configx.Provider) *configx.Provider

func (*NoOp) Network added in v0.0.458

func (d *NoOp) Network(ctx context.Context, network uuid.UUID) uuid.UUID

type Provider added in v0.0.387

type Provider interface {
	Contextualizer() Contextualizer
}

type Static added in v0.0.387

type Static struct {
	NID uuid.UUID
	C   *configx.Provider
}

func (*Static) Config added in v0.0.387

func (d *Static) Config(ctx context.Context, config *configx.Provider) *configx.Provider

func (*Static) Network added in v0.0.387

func (d *Static) Network(ctx context.Context, network uuid.UUID) uuid.UUID

type TestContextualizer added in v0.0.387

type TestContextualizer struct{}

TestContextualizer is a mock implementation of the Contextualizer interface.

func (*TestContextualizer) Config added in v0.0.387

Config returns the config for the given context.

func (*TestContextualizer) Network added in v0.0.387

func (d *TestContextualizer) Network(ctx context.Context, network uuid.UUID) uuid.UUID

Network returns the network id for the given context.

Jump to

Keyboard shortcuts

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