RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet. If prefix is an empty string we will register consul flags with no prefix and the store flag with the prefix ring, so ring.store. For everything else we pass the prefix to the Consul flags. If prefix is not an empty
(flagsPrefix, defaultPrefix string, f *flag.FlagSet)
| 67 | // to the Consul flags. |
| 68 | // If prefix is not an empty string it should end with a period. |
| 69 | func (cfg *Config) RegisterFlagsWithPrefix(flagsPrefix, defaultPrefix string, f *flag.FlagSet) { |
| 70 | // We need Consul flags to not have the ring prefix to maintain compatibility. |
| 71 | // This needs to be fixed in the future (1.0 release maybe?) when we normalize flags. |
| 72 | // At the moment we have consul.<flag-name>, and ring.store, going forward it would |
| 73 | // be easier to have everything under ring, so ring.consul.<flag-name> |
| 74 | cfg.Consul.RegisterFlags(f, flagsPrefix) |
| 75 | cfg.Etcd.RegisterFlagsWithPrefix(f, flagsPrefix) |
| 76 | cfg.Multi.RegisterFlagsWithPrefix(f, flagsPrefix) |
| 77 | |
| 78 | if flagsPrefix == "" { |
| 79 | flagsPrefix = "ring." |
| 80 | } |
| 81 | |
| 82 | // Allow clients to override default store by setting it before calling this method. |
| 83 | if cfg.Store == "" { |
| 84 | cfg.Store = "consul" |
| 85 | } |
| 86 | |
| 87 | f.StringVar(&cfg.Prefix, flagsPrefix+"prefix", defaultPrefix, "The prefix for the keys in the store. Should end with a /.") |
| 88 | f.StringVar(&cfg.Store, flagsPrefix+"store", cfg.Store, "Backend storage to use for the ring. Supported values are: consul, etcd, inmemory, memberlist, multi.") |
| 89 | } |
| 90 | |
| 91 | // Client is a high-level client for key-value stores (such as Etcd and |
| 92 | // Consul) that exposes operations such as CAS and Watch which take callbacks. |