Documentation
¶
Index ¶
- func Get() *viper.Viper
- func LoadEnvironment(confFn func(environment *Environment))
- func LoadEnvironmentsWithDefaults()
- type Environment
- func (e *Environment) AddFile(file File)
- func (e *Environment) LoadFileBytes(key, filename string)
- func (e *Environment) SetDefaultFileName(fileName string)
- func (e *Environment) SetDefaultFileType(fileType string)
- func (e *Environment) SetEnvVariable(envName string)
- func (e *Environment) SetRootPath(path string)
- func (e *Environment) UseDefaultFiles(use bool)
- func (e *Environment) UseProfiles(use bool)
- type File
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadEnvironment ¶
func LoadEnvironment(confFn func(environment *Environment))
environment.LoadFileBytes("file", "file.txt") })
func LoadEnvironmentsWithDefaults ¶
func LoadEnvironmentsWithDefaults()
LoadEnvironmentsWithDefaults loads the environment with default values example: LoadEnvironmentsWithDefaults()
the default values are:
UseProfiles(true) UseDefaultFiles(true) SetDefaultFileType("yml") SetDefaultFileName("application") SetRootPath("./resources") SetEnvVariable("ENVIRONMENT") AddFile(File{ Name: "application", Type: "yml", Path: "./resources", })
This function expects a file called application.yml and a file called application.%profile%.yml in the root path example: application.yml, application.dev.yml, application.prod.yml
Types ¶
type Environment ¶
type Environment struct { Files []File // contains filtered or unexported fields }
Environment is a struct that contains a list of files to be loaded and a list of environment variables to be loaded
func (*Environment) AddFile ¶
func (e *Environment) AddFile(file File)
AddFile adds a file to the environment
func (*Environment) LoadFileBytes ¶
func (e *Environment) LoadFileBytes(key, filename string)
LoadFileBytes loads a file to the environment example: LoadFileBytes("file", "file.txt") the file will be available in the environment as a byte array example: environment.Get("file") or can be injected in a struct using the tag `inject:"file:key"` and instantiated using the hidra/typed package example: typed.New[target struct]() or typed.InjectIn(&target struct)
func (*Environment) SetDefaultFileName ¶
func (e *Environment) SetDefaultFileName(fileName string)
SetDefaultFileName sets the default file name example: application, config, settings
func (*Environment) SetDefaultFileType ¶
func (e *Environment) SetDefaultFileType(fileType string)
SetDefaultFileType sets the default file type example: yml, json, toml
func (*Environment) SetEnvVariable ¶
func (e *Environment) SetEnvVariable(envName string)
SetEnvVariable sets the environment variable to be used example: ENV, PROFILE, APP_ENV the default is ENVIROMENT
func (*Environment) SetRootPath ¶
func (e *Environment) SetRootPath(path string)
SetRootPath sets the root path of the environment example: ./config, ./settings, ./resources the default is ./resources
func (*Environment) UseDefaultFiles ¶
func (e *Environment) UseDefaultFiles(use bool)
UseDefaultFiles sets if the environment will use default files like application.yml and application.%profile%.yml example: application.yml, application.dev.yml, application.prod.yml
func (*Environment) UseProfiles ¶
func (e *Environment) UseProfiles(use bool)
UseProfiles sets if the environment will use profiles