autosklo/config.go

46 lines
1.4 KiB
Go
Raw Normal View History

2024-01-05 14:49:46 +00:00
package main
import (
"log"
"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
)
const configPath = ".env"
type Config struct {
CouchDBUsername string `envconfig:"COUCHDB_USERNAME" required:"true"`
CouchDBPassword string `envconfig:"COUCHDB_PASSWORD" required:"true"`
CouchDBProto string `envconfig:"COUCHDB_PROTO" required:"true" default:"https"`
CouchDBPort string `envconfig:"COUCHDB_PORT" required:"true" default:""`
CouchDBHost string `envconfig:"COUCHDB_HOST" required:"true"`
CouchDBName string `envconfig:"COUCHDB_DBNAME" default:"autosklo"`
SMTPHostname string `envconfig:"SMTP_HOSTNAME" default:"mailer.rosti.cz"`
SMTPUsername string `envconfig:"SMTP_USERNAME" default:"web@nove-autosklo.cz"`
SMTPPassword string `envconfig:"SMTP_PASSWORD" require:"true"`
SMTPPort int `envconfig:"SMTP_PORT" default:"587"`
EmailTo string `envconfig:"EMAIL_TO" default:"web@nove-autosklo.cz"`
EmailFrom string `envconfig:"EMAIL_FROM" default:"no-reply@nove-autosklo.cz"`
EmailSubject string `envconfig:"EMAIL_SUBJECT" default:"[WEB] Zpráva z rezervačního formuláře"`
}
func getConfig() Config {
var config Config
if len(configPath) != 0 {
err := godotenv.Load(configPath)
if err != nil {
log.Fatalln(err)
}
}
err := envconfig.Process("", &config)
if err != nil {
log.Fatalln(err)
}
return config
}