32 lines
907 B
Go
32 lines
907 B
Go
package config
|
|
|
|
import "github.com/ilyakaznacheev/cleanenv"
|
|
|
|
type Config struct {
|
|
Debug bool `toml:"debug" env:"DEBUG" env-default:"false"`
|
|
Pipeline Pipeline `toml:"pipeline"`
|
|
Outputs []Output `toml:"outputs"`
|
|
}
|
|
|
|
type Output struct {
|
|
Type string `toml:"type" env:"OUTPUT_TYPE"`
|
|
Target string `toml:"target" env:"OUTPUT_TARGET"`
|
|
}
|
|
|
|
type Pipeline struct {
|
|
Width int `toml:"width" env:"PIPELINE_WIDTH" env-default:"50"`
|
|
Height int `toml:"height" env:"PIPELINE_HEIGHT" env-default:"50"`
|
|
}
|
|
|
|
func LoadConfig(path string) (*Config, error) {
|
|
var cfg Config
|
|
err := cleanenv.ReadConfig(path, &cfg)
|
|
if err != nil {
|
|
// It's often useful to ignore "file not found" errors if you want
|
|
// to allow configuration purely via environment variables.
|
|
// However, the specific behavior depends on the application's needs.
|
|
// For now, we'll return the error.
|
|
return nil, err
|
|
}
|
|
return &cfg, nil
|
|
}
|