feat: init repo

This commit is contained in:
2023-03-01 22:23:04 +01:00
commit 8cb3e3b9f6
6 changed files with 180 additions and 0 deletions

32
cfg/cfg.go Normal file
View File

@@ -0,0 +1,32 @@
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"`
}
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
}