This commit is contained in:
2023-07-05 22:07:10 +02:00
parent 0ba69b5496
commit b2e65a9df0
15 changed files with 645 additions and 0 deletions

32
kit/config/config.go Normal file
View File

@@ -0,0 +1,32 @@
package config
import (
"log"
"gitea.urkob.com/urko/prosody-password/kit"
"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
)
type Config struct {
Domain string `required:"true" split_words:"true"`
ApiPort string `required:"false" split_words:"true"`
Views string `required:"false" split_words:"true"`
}
func NewConfig(envFile string) *Config {
if envFile != "" {
err := godotenv.Load(kit.RootDir() + "/" + envFile)
if err != nil {
log.Fatalln("godotenv.Load:", err)
}
}
cfg := &Config{}
err := envconfig.Process("", cfg)
if err != nil {
log.Fatalf("envconfig.Process: %s\n", err)
}
return cfg
}