Documentation ¶
Index ¶
- type Config
- type Environment
- func (env *Environment) Get(key string) interface{}
- func (env *Environment) GetBool(key string) bool
- func (env *Environment) GetDuration(key string) time.Duration
- func (env *Environment) GetFloat64(key string) float64
- func (env *Environment) GetInt(key string) int
- func (env *Environment) GetString(key string) string
- func (env *Environment) GetStringMap(key string) map[string]interface{}
- func (env *Environment) GetStringSlice(key string) []string
- func (env *Environment) GetTime(key string) time.Time
- func (env *Environment) Viper() *v.Viper
- type EnvironmentScope
- type StartConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
Defines the instance type to be used to retrieve environment variables.
func NewConfig ¶
func NewConfig(cfg StartConfig) *Config
Creates a new `Config` instance, given a `StartConfig` Loads the .env file with the given path. Automatically add environment variables (.env files included).
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
Defines the environment variables reader.
var Env *Environment
Instance to read environment variables.
func LoadEnv ¶
func LoadEnv(prefix, path string) *Environment
Loads the .env file with the given path. Automatically add environment variables (.env files included).
func (*Environment) Get ¶
func (env *Environment) Get(key string) interface{}
Given the right key, it returns any value from an environment variable as an interface.
func (*Environment) GetBool ¶
func (env *Environment) GetBool(key string) bool
Given the key, it returns the environment variable value as bool.
func (*Environment) GetDuration ¶
func (env *Environment) GetDuration(key string) time.Duration
Given the key, it returns the environment variable value as time.Duration.
func (*Environment) GetFloat64 ¶
func (env *Environment) GetFloat64(key string) float64
Given the key, it returns the environment variable value as float64.
func (*Environment) GetInt ¶
func (env *Environment) GetInt(key string) int
Given the key, it returns the environment variable value as int.
func (*Environment) GetString ¶
func (env *Environment) GetString(key string) string
Given the key, it returns the environment variable value as a string.
func (*Environment) GetStringMap ¶
func (env *Environment) GetStringMap(key string) map[string]interface{}
Given the right key, it returns the the environment variable value as a map, with string as key and interface as value.
func (*Environment) GetStringSlice ¶
func (env *Environment) GetStringSlice(key string) []string
Given the key, it returns the environment variable value as a string slice.
func (*Environment) GetTime ¶
func (env *Environment) GetTime(key string) time.Time
Given the key, it returns the environment variable value as time.Time.
func (*Environment) Viper ¶
func (env *Environment) Viper() *v.Viper
It returns the Viper instance to handle environment variables functionality
type EnvironmentScope ¶ added in v0.0.3
type EnvironmentScope struct {
Env *Environment
}
func LoadScopedEnv ¶ added in v0.0.3
func LoadScopedEnv(key, prefix, path string) (*EnvironmentScope, error)
Creates a new environment variables scope and loads the .env file with the given path into the new scope.
func Scope ¶ added in v0.0.3
func Scope(key string) *EnvironmentScope
Retrives the environment scope with the given key.
type StartConfig ¶
type StartConfig struct { // Defines a prefix that environment variables will use. // If your prefix is mtz, your environment variables should start with MTZ_ Prefix string // The path of the .env file to be loaded. // It is relative to the application entrypoint, e.g: main.go. ConfigPath string }
Defines all the necessary input to load environment variables.