41 lines
654 B
Go
41 lines
654 B
Go
package helpers
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/golobby/dotenv"
|
|
)
|
|
|
|
type Config struct {
|
|
DownloadLocation string `env:"DOWNLOAD_LOCATION"`
|
|
Website struct {
|
|
Username string `env:"WEBSITE_USERNAME"`
|
|
Password string `env:"WEBSITE_PASSWORD"`
|
|
}
|
|
Debug struct {
|
|
DisableHeadless bool `env:"DEBUG_DISABLE_HEADLESS"`
|
|
}
|
|
}
|
|
|
|
var configParsed bool
|
|
var config Config
|
|
|
|
func GetConfig() (Config, error) {
|
|
if configParsed {
|
|
return config, nil
|
|
}
|
|
|
|
file, err := os.Open(".env")
|
|
if err != nil {
|
|
return config, err
|
|
}
|
|
|
|
err = dotenv.NewDecoder(file).Decode(&config)
|
|
if err != nil {
|
|
return config, err
|
|
}
|
|
|
|
configParsed = true
|
|
|
|
return config, err
|
|
}
|