mirror of
https://github.com/KevinMidboe/traefik-etcd-advertiser.git
synced 2025-10-29 09:50:20 +00:00
Return error if etcd_endpoints variable is missing
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"log"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
@@ -9,18 +10,21 @@ import (
|
||||
|
||||
// Config contains environment variables.
|
||||
type Config struct {
|
||||
EtcdEndpoint string `envconfig:"ETCD_ENDPOINTS"`
|
||||
EtcdEndpoint string `envconfig:"ETCD_ENDPOINTS"`
|
||||
}
|
||||
|
||||
// LoadConfig reads environment variables, populates and returns Config.
|
||||
func LoadConfig() (*Config, error) {
|
||||
if err := godotenv.Load(); err != nil {
|
||||
log.Println("No .env file found")
|
||||
slog.Warn("No .env file found")
|
||||
}
|
||||
|
||||
var c Config
|
||||
|
||||
err := envconfig.Process("", &c)
|
||||
|
||||
if len(c.EtcdEndpoint) < 1 {
|
||||
err = fmt.Errorf("missing variable ETCD_ENDPOINTS, not set")
|
||||
}
|
||||
|
||||
return &c, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user