first commit
This commit is contained in:
commit
4b1861fa9b
14 changed files with 811 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 {
|
||||
DryRun bool `env:"DRY_RUN"`
|
||||
Hetzner struct {
|
||||
ApiToken string `env:"HETZNER_API_TOKEN"`
|
||||
}
|
||||
}
|
||||
|
||||
var configParsed bool
|
||||
var config Config
|
||||
|
||||
func GetConfig() (Config, error) {
|
||||
if configParsed {
|
||||
return config, nil
|
||||
}
|
||||
|
||||
return parseConfig()
|
||||
}
|
||||
|
||||
func parseConfig() (Config, error) {
|
||||
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