Documentation ¶
Overview ¶
Package resolve provides a shorthand resolution for command context, config and logger as a one-liner.
This factorizes common CLI use-cases where injected stuff boils down to just a logger and a configuration registry.
Index ¶
- func InjectedSLogConfig(c *cobra.Command, opts ...Option) (context.Context, *slog.Logger, *viper.Viper)
- func InjectedZapConfig(c *cobra.Command, opts ...Option) (context.Context, *zap.Logger, *viper.Viper)
- func ReinjectSLogger(c *cobra.Command, slg *slog.Logger) context.Context
- func ReinjectZapLogger(c *cobra.Command, zlg *zap.Logger) context.Context
- func RelevelInjectedZapLogger(c *cobra.Command, level string, opts ...Option) (context.Context, *zap.Logger)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InjectedSLogConfig ¶
func InjectedSLogConfig(c *cobra.Command, opts ...Option) (context.Context, *slog.Logger, *viper.Viper)
ResolveInjectSLogConfig returns in a single call the standard structure logger and viper config stored in the command context as injectables.
Options may specify defaults whenever these items cannot be found in the context.
func InjectedZapConfig ¶
func InjectedZapConfig(c *cobra.Command, opts ...Option) (context.Context, *zap.Logger, *viper.Viper)
ResolveInjectZapConfig returns in a single call the zap logger and viper config stored in the command context as injectables.
Options may specify defaults whenever these items cannot be found in the context.
func ReinjectSLogger ¶
ReinjectSLogger updates the command context with a new logger.
It returns the new context of this command.
This is useful for instance to relevel a logger after CLI flags parsing.
func ReinjectZapLogger ¶
ReinjectZapLogger updates the command context with a new logger.
It returns the new context of this command.
This is useful for instance to relevel a logger after CLI flags parsing.
func RelevelInjectedZapLogger ¶
func RelevelInjectedZapLogger(c *cobra.Command, level string, opts ...Option) (context.Context, *zap.Logger)
RelevelInjectedZapLogger reinjects into the command's context a relevel logger with a new level.
NOTE: the new level can only be higher (more restrictive) than the initially configured one, otherwise this is a no-op.
Types ¶
type Option ¶
type Option func(*options)
Option to tune the retrieval of injected dependencies from a command's context
func WithConfigDefaulter ¶
WithConfigDefaulter applies a default config generation whenever the injected context is not found.
This guarantees on the presence of a config.
func WithSLoggerDefaulter ¶
WithSLoggerDefaulter applies a default logger generation whenever the injected context is not found.
This guarantees the presence of a logger.
func WithZapLoggerDefaulter ¶
WithZapLoggerDefaulter applies a default logger generation whenever the injected context is not found.
This guarantees the presence of a logger.