Documentation ¶
Index ¶
- func ConfigFromContext(ctx context.Context, defaulters ...func() *viper.Viper) *viper.Viper
- func SLoggerFromContext(ctx context.Context, defaulters ...func() *slog.Logger) *slog.Logger
- func ZapLoggerFromContext(ctx context.Context, defaulters ...func() *zap.Logger) *zap.Logger
- type Config
- type ContextInjectable
- type SLogger
- type ZapLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigFromContext ¶
ConfigFromContext retrieves a configuration registry from the context.
An optional defaulter can be added to deal with a non-existing config.
func SLoggerFromContext ¶ added in v0.1.3
SLoggerFromContext retrieves a standard structured logger from the context.
Optional defaulters can be added to deal with a non-existing logger.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config can wrap a viper.Viper configuration in the context
func (Config) FromContext ¶
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 SLogger ¶ added in v0.1.3
type SLogger struct {
// contains filtered or unexported fields
}
func NewSLogger ¶ added in v0.1.3
func (SLogger) FromContext ¶ added in v0.1.3
type ZapLogger ¶
type ZapLogger struct {
// contains filtered or unexported fields
}
func NewZapLogger ¶ added in v0.2.0
func (ZapLogger) FromContext ¶ added in v0.2.0
Click to show internal directories.
Click to hide internal directories.