injectable

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: Apache-2.0 Imports: 2 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigFromContext

func ConfigFromContext(ctx context.Context, defaulters ...func() *viper.Viper) *viper.Viper

ConfigFromContext retrieves a configuration registry from the context.

Optional defaulters can be added to deal with a non-existing config.

Types

type Config

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

Config can wrap a viper.Viper configuration in the context

func NewConfig

func NewConfig(v *viper.Viper) *Config

func (*Config) Context

func (c *Config) Context(ctx context.Context) context.Context

func (Config) FromContext

func (c Config) FromContext(ctx context.Context) interface{}

type ContextInjectable

type ContextInjectable interface {
	// Context builds a context with the injected value
	Context(context.Context) context.Context

	// FromContext retrieves the injected value from the context.
	//
	// It should work even if the receiver is zero value.
	FromContext(context.Context) interface{}
}

ContextInjectable knows how to retrieve a value from a Context.

Users of the github.com/fredbi/go-cli/cli package can define their own injections via the context.

NOTE: every such type should declare their own key type to avoid conflicts inside the context.

For example:

type commandCtxKey uint8
const ctxConfig commandCtxKey = iota + 1

type ZapLogger

type ZapLogger struct {
}

TODO: puts logger in context ZapLogger can wrap a zap logger in the context

Jump to

Keyboard shortcuts

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