first commit
This commit is contained in:
commit
5576528bcf
10 changed files with 386 additions and 0 deletions
41
helpers/config.go
Normal file
41
helpers/config.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue