btc-pay-checker/kit/cfg/config.go

49 lines
1.6 KiB
Go
Raw Permalink Normal View History

2023-07-19 11:47:46 +02:00
package cfg
import (
"log"
"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
)
type Config struct {
LogFile bool `required:"false" split_words:"true"`
Host string `required:"true" split_words:"true"`
DbAddress string `required:"true" split_words:"true"`
DbName string `required:"true" split_words:"true"`
OrdersCollection string `required:"true" split_words:"true"`
RpcZmq string `required:"true" split_words:"true"`
RpcAuth string `required:"true" split_words:"true"`
RpcHost string `required:"true" split_words:"true"`
WalletAddress string `required:"true" split_words:"true"`
2023-07-19 21:20:59 +02:00
WebhookUrl string `required:"false" split_words:"true"`
2023-07-19 11:47:46 +02:00
ApiPort string `required:"true" split_words:"true"`
Views string `required:"true" split_words:"true"`
ConversorApi string `required:"true" split_words:"true"`
DollarRateApi string `required:"true" split_words:"true"`
MailHost string `required:"true" split_words:"true"`
MailPort string `required:"true" split_words:"true"`
MailUser string `required:"true" split_words:"true"`
MailPassword string `required:"true" split_words:"true"`
MailFrom string `required:"true" split_words:"true"`
MailTo string `required:"false" split_words:"true"`
}
func NewConfig(envFile string) *Config {
if envFile != "" {
err := godotenv.Load(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
}