configurator

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: MIT Imports: 8 Imported by: 11

Documentation

Index

Constants

View Source
const (
	ConfigPathFieldName = "config.path"
	ConfigNameFieldName = "config.name"
	ConfigTypeFieldName = "config.type"

	ConfigPathDefault        = "."
	ConfigNameDefault        = "config"
	ConfigTypeDefault        = "yaml"
	EnvKeyReplaceFromDefault = "."
	EnvKeyReplaceToDefault   = "_"
)

Variables

View Source
var Component = &app.Component{
	Constructor: app.Constructor(func(container container.Container) error {
		return container.Provides(
			NewConfig,
			NewViperDecorator,
			func(viperDecorator *ViperDecorator) Configurator { return viperDecorator },
		)
	}),
	BindFlags: app.BindFlags(func(flagSet *pflag.FlagSet, container container.Container) error {
		return container.Invoke(func(config *Config) {
			flagSet.StringVar(&config.Path, ConfigPathFieldName, ConfigPathDefault, "path to the directory where the config file is located")
			flagSet.StringVar(&config.Name, ConfigNameFieldName, ConfigNameDefault, "config file name")
			flagSet.StringVar(&config.Type, ConfigTypeFieldName, ConfigTypeDefault, "config file format")
		})
	}),
	Run: app.Run(func(container container.Container) error {
		return container.Invoke(Configuration)
	}),
}

Functions

This section is empty.

Types

type Config

type Config struct {
	Path              string
	Name              string
	Type              string
	EnvKeyReplaceFrom string
	EnvKeyReplaceTo   string
}

func Configuration

func Configuration(config *Config) *Config

func NewConfig

func NewConfig() *Config

type Configurator

type Configurator interface {
	GetString(string) string
	GetBool(string) bool
	GetInt(string) int
	GetInt8(string) int8
	GetInt16(string) int16
	GetInt32(string) int32
	GetInt64(string) int64
	GetUint(string) uint
	GetUint8(string) uint8
	GetUint16(string) uint16
	GetUint32(string) uint32
	GetUint64(string) uint64
	GetFloat32(string) float32
	GetFloat64(string) float64
	GetTime(string) time.Time
	GetDuration(string) time.Duration
	GetIntSlice(string) []int
	GetStringSlice(string) []string
	GetStringMap(string) map[string]interface{}
	GetStringMapString(string) map[string]string
	GetStringMapStringSlice(string) map[string][]string
	GetSizeInBytes(string) uint

	SetDefault(string, interface{})

	ReadConfig() error
}

type ViperDecorator

type ViperDecorator struct {
	*viper.Viper
	// contains filtered or unexported fields
}

func NewViperDecorator

func NewViperDecorator(config *Config) (*ViperDecorator, error)

func (*ViperDecorator) GetFloat32

func (v *ViperDecorator) GetFloat32(key string) float32

func (*ViperDecorator) GetInt16

func (v *ViperDecorator) GetInt16(key string) int16

func (*ViperDecorator) GetInt8

func (v *ViperDecorator) GetInt8(key string) int8

func (*ViperDecorator) GetUint16

func (v *ViperDecorator) GetUint16(key string) uint16

func (*ViperDecorator) GetUint8

func (v *ViperDecorator) GetUint8(key string) uint8

func (*ViperDecorator) ReadConfig

func (v *ViperDecorator) ReadConfig() error

Jump to

Keyboard shortcuts

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