| 1 |
Description: Read configuration from file |
| 2 |
The original service is hardcoding a lot of values, let's read it from a |
| 3 |
.ini file. |
| 4 |
Author: Thomas Goirand <[email protected]> |
| 5 |
Forwarded: no |
| 6 |
Last-Update: 2019-12-10 |
| 7 |
|
| 8 |
--- golang-github-coreos-discovery-etcd-io-2.0.0+git2019.04.19.git.78fb45d3c9.orig/discovery.go |
| 9 |
+++ golang-github-coreos-discovery-etcd-io-2.0.0+git2019.04.19.git.78fb45d3c9/discovery.go |
| 10 |
@@ -13,6 +13,7 @@ import ( |
| 11 |
"github.com/coreos/go-systemd/activation" |
| 12 |
"github.com/spf13/pflag" |
| 13 |
"github.com/spf13/viper" |
| 14 |
+ "github.com/go-ini/ini" |
| 15 |
) |
| 16 |
|
| 17 |
func fail(err string) { |
| 18 |
@@ -51,9 +52,15 @@ func init() { |
| 19 |
viper.SetEnvPrefix("disc") |
| 20 |
viper.AutomaticEnv() |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
+ cfg, err := ini.Load("/etc/etcd-discovery/etcd-discovery.conf") |
| 26 |
+ if err != nil { |
| 27 |
+ fmt.Printf("Fail to read file: %v", err) |
| 28 |
+ os.Exit(1) |
| 29 |
+ } |
| 30 |
+ |
| 31 |
+ pflag.StringP("etcd", "e", cfg.Section("etcd").Key("endpoint_location").String(), "etcd endpoint location") |
| 32 |
+ pflag.StringP("host", "h", cfg.Section("server").Key("prefix_url").String(), "discovery url prefix") |
| 33 |
+ pflag.StringP("addr", "a", cfg.Section("server").Key("web_service_address").String(), "web service address") |
| 34 |
|
| 35 |
viper.BindPFlag("etcd", pflag.Lookup("etcd")) |
| 36 |
viper.BindPFlag("host", pflag.Lookup("host")) |