env

package
v0.0.0-...-080604a Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get() *viper.Viper

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

type File

type File struct {
	Name string
	Type string
	Path string
}

Jump to

Keyboard shortcuts

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