config

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind[T any](c *T, prefix string, v *viper.Viper) *T

Bind configuration section if it implements Binder interface.

func LoadRemoteSecret

func LoadRemoteSecret(name string) (string, error)

LoadRemoteSecret loads a remote secret from configuration provided in environment variable.

Environment variable name is expected to be in the format:

<name>_FILE - path to the file containing the secret

Types

type Binder

type Binder interface {
	Bind(prefix string, v *viper.Viper)
}

Binder is an interface that can be implemented by configuration sections to bind to configuration file.

type Cache

type Cache struct {
	Type             cache.CacheType `mapstructure:"type" validate:"required,oneof=memory redis redis-cluster"`
	TTL              time.Duration   `mapstructure:"ttl" validate:"omitempty,min=0"`
	ConnectionString string          `mapstructure:"connection" validate:"omitempty"`
	Password         string          `mapstructure:"password" validate:"omitempty"`
	KeyPrefix        string          `mapstructure:"key_prefix" validate:"omitempty"`
}

func (*Cache) Bind

func (c *Cache) Bind(prefix string, v *viper.Viper)

Bind cache configuration section.

func (*Cache) Validate

func (c *Cache) Validate(valid *validation.Validate) error

Validate cache configuration section.

type CmdBinder added in v0.3.0

type CmdBinder interface {
	BindCmd(cmd *cobra.Command, v *viper.Viper)
}

CmdBinder is an interface that can be implemented by configuration sections to bind to command line arguments.

type Configurable

type Configurable interface {
	Core() *Configuration
	Loaded(*Configuration)
}

Configurable is an interface that can be implemented by extended configuration.

type Configuration

type Configuration struct {

	// Cache configuration section.
	Cache *Cache
	// contains filtered or unexported fields
}

Configuration for the application.

func New

func New() *Configuration

New returns a new configuration.

func (*Configuration) Bind

func (c *Configuration) Bind(_ string, v *viper.Viper)

Bind binds configuration section to viper.

func (*Configuration) Core

func (c *Configuration) Core() *Configuration

Core returns the core configuration.

func (*Configuration) Load

func (c *Configuration) Load(cmd *cobra.Command, config any, environment string) error

Load loads the configuration from the provided path.

func (*Configuration) Loaded

func (c *Configuration) Loaded(*Configuration)

Loaded receives loaded core configuration.

func (*Configuration) Ready

func (c *Configuration) Ready() bool

Ready returns true if the configuration has been loaded.

func (*Configuration) SetConfigDirName

func (c *Configuration) SetConfigDirName(dirName string)

SetConfigDirName sets the name of the directory where the config file is located under common config locations.

func (*Configuration) SetConfigFile

func (c *Configuration) SetConfigFile(path string)

SetConfigFile explicitly defines the path, name and extension of the config file.

func (*Configuration) SetConfigName

func (c *Configuration) SetConfigName(name string)

SetConfigName sets name for the config file. Does not include extension.

func (*Configuration) Validate

func (c *Configuration) Validate(validate *validation.Validate) error

Validate the configuration.

type Validatable

type Validatable interface {
	Validate(*validation.Validate) error
}

Validatable is an interface that can be implemented by configuration section to validate the configuration.

Jump to

Keyboard shortcuts

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