Description: Read configuration from file The original service is hardcoding a lot of values, let's read it from a .ini file. Author: Thomas Goirand Forwarded: no Last-Update: 2019-12-10 --- golang-github-coreos-discovery-etcd-io-2.0.0+git2019.04.19.git.78fb45d3c9.orig/discovery.go +++ golang-github-coreos-discovery-etcd-io-2.0.0+git2019.04.19.git.78fb45d3c9/discovery.go @@ -13,6 +13,7 @@ import ( "github.com/coreos/go-systemd/activation" "github.com/spf13/pflag" "github.com/spf13/viper" + "github.com/go-ini/ini" ) func fail(err string) { @@ -51,9 +52,15 @@ func init() { viper.SetEnvPrefix("disc") viper.AutomaticEnv() - pflag.StringP("etcd", "e", "http://127.0.0.1:2379", "etcd endpoint location") - pflag.StringP("host", "h", "https://discovery.etcd.io", "discovery url prefix") - pflag.StringP("addr", "a", ":8087", "web service address") + cfg, err := ini.Load("/etc/etcd-discovery/etcd-discovery.conf") + if err != nil { + fmt.Printf("Fail to read file: %v", err) + os.Exit(1) + } + + pflag.StringP("etcd", "e", cfg.Section("etcd").Key("endpoint_location").String(), "etcd endpoint location") + pflag.StringP("host", "h", cfg.Section("server").Key("prefix_url").String(), "discovery url prefix") + pflag.StringP("addr", "a", cfg.Section("server").Key("web_service_address").String(), "web service address") viper.BindPFlag("etcd", pflag.Lookup("etcd")) viper.BindPFlag("host", pflag.Lookup("host"))