config

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Service = dependency.Service{
	Dependencies: fx.Provide(
		NewFactory().Configure,
	),
	Constructor: func(config *viper.Viper) dependency.ConfigGetter {
		return config
	},
}

Service provides the config framework as a *viper.Viper and a framework.ConfigGetter

Functions

func ConfigureViper

func ConfigureViper(config Viper, cmd *cobra.Command, replacer *strings.Replacer) error

ConfigureViper is a function that will configure viper

Types

type Factory

type Factory struct {
	Replacer   *strings.Replacer
	ConfigFunc func(config Viper, cmd *cobra.Command, replacer *strings.Replacer) error
}

Factory is a type that can produce new instances of the *viper.Viper type

func NewFactory

func NewFactory() Factory

NewFactory gives a new instance of the Factory type with a string.Replacer that will replace - or . with _ when in an environment variable, it also sets the ConfigFunc to be ConfigureViper function

func (Factory) Configure

func (f Factory) Configure(cmd *cobra.Command) (*viper.Viper, error)

Configure will produce a *viper.Viper type configured by the ConfigFunc held by the Factory

type Viper

type Viper interface {
	AutomaticEnv()
	SetEnvKeyReplacer(r *strings.Replacer)
	BindPFlags(flags *pflag.FlagSet) error
}

Viper is an interface that the *viper.Viper type adheres to, this is to enable the package to be thoroughly test

Jump to

Keyboard shortcuts

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