env

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 15 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrEnvDoesNotExist is returned when an environment that does not exist in the config is requested
	ErrEnvDoesNotExist = errors.New("environment does not exist in this environments list")
	// ErrEnvNotDefined is returned if the environment was found but had no config, this usually means poor conf
	ErrEnvNotDefined = errors.New("environment was found but not defined")
	// ErrNoEnvironmentsDefined is returned when trying to save an empty config
	ErrNoEnvironmentsDefined = errors.New("no environments defined, nothing to write")
	// ErrInvalidEnvironmentName is returned if an environment is trying to be set with a blank name
	ErrInvalidEnvironmentName = errors.New("environment name cannot be blank")
)
View Source
var Default = Env{
	Name: "development",
}

Default is the default values for a environment

Functions

func SourceVariables added in v1.0.0

func SourceVariables(flagpath string) error

SourceVariables will find the environment files for configuration and import their environment variables into the current running process

Types

type Conf

type Conf struct {
	Envs map[string]*Env
	// contains filtered or unexported fields
}

Conf is a map of configurations to their environment name.

func Load

func Load(configPath string) (Conf, error)

Load will read in the file from the configPath provided and then unmarshal the data into conf.

func New

func New(configPath string) Conf

New will build a new blank config

func (*Conf) Get

func (c *Conf) Get(name string, overrides ...Env) (*Env, error)

Get will check if an environment exists and then return it. If the environment does not exists it will return an error

func (Conf) Save

func (c Conf) Save() error

Save will write out the config to a file.

func (*Conf) Set

func (c *Conf) Set(name string, initial Env, overrides ...Env) (*Env, error)

Set will set the environment value and then mixin any overrides passed in. The os overrides and defaults will also be mixed into the new environment

type Env

type Env struct {
	Name         string        `yaml:"-" json:"-" env:"-"`
	Password     string        `yaml:"password,omitempty" json:"password,omitempty" env:"THEMEKIT_PASSWORD"`
	ThemeID      string        `yaml:"theme_id,omitempty" json:"theme_id,omitempty" env:"THEMEKIT_THEME_ID"`
	Domain       string        `yaml:"store" json:"store" env:"THEMEKIT_STORE"`
	Directory    string        `yaml:"directory,omitempty" json:"directory,omitempty" env:"THEMEKIT_DIRECTORY"`
	IgnoredFiles []string      `yaml:"ignore_files,omitempty" json:"ignore_files,omitempty" env:"THEMEKIT_IGNORE_FILES" envSeparator:":"`
	Proxy        string        `yaml:"proxy,omitempty" json:"proxy,omitempty" env:"THEMEKIT_PROXY"`
	Ignores      []string      `yaml:"ignores,omitempty" json:"ignores,omitempty" env:"THEMEKIT_IGNORES" envSeparator:":"`
	Timeout      time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" env:"THEMEKIT_TIMEOUT"`
	ReadOnly     bool          `yaml:"readonly,omitempty" json:"readonly,omitempty" env:"-"`
	Notify       string        `yaml:"notify,omitempty" json:"notify,omitempty" env:"THEMEKIT_NOTIFY"`
}

Env is the structure of a configuration for an environment.

Jump to

Keyboard shortcuts

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