2023-03-01 22:23:04 +01:00
|
|
|
package cfg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/joho/godotenv"
|
|
|
|
"github.com/kelseyhightower/envconfig"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
Page string `required:"true" split_words:"true"`
|
|
|
|
AdminUser string `required:"true" split_words:"true"`
|
|
|
|
Password string `required:"true" split_words:"true"`
|
|
|
|
LogFile bool `required:"true" split_words:"true"`
|
2023-03-04 21:56:47 +01:00
|
|
|
Bin string `required:"true" split_words:"true"`
|
2023-03-01 22:23:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewConfig(envFilePath string) *Config {
|
|
|
|
if envFilePath != "" {
|
|
|
|
err := godotenv.Load(envFilePath)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("environment variable ENV is empty and an error occurred while loading the .env file\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg := &Config{}
|
|
|
|
err := envconfig.Process("", cfg)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("envconfig.Process: %s\n", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cfg
|
|
|
|
}
|