Skip to content

Commit 57c99ce

Browse files
authored
Merge pull request #4 from coretech/increase_timeout
Add ability to provide http timeout for client via CLI option
2 parents cd57e91 + 0f46c15 commit 57c99ce

File tree

6 files changed

+19
-1
lines changed

6 files changed

+19
-1
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,15 @@ This is the number of seconds you want Gonsul to wait between checks on the repo
308308
This is the file extensions that Gonsul should consider as inputs to populate our Consul. Please set each extension
309309
without the dot, and separate each extension with a comma.
310310

311+
312+
### `--timeout`
313+
> `require:` **no**
314+
> `default:` **5**
315+
> `example:` **`--timeout=20`**
316+
317+
The number of seconds for the client to wait for a response from Consul
318+
319+
311320
## Gonsul Exit Codes
312321
Whenever an error occurs, and Gonsul exits with a code other than 0, we try to return a meaningful code, such as:
313322

configuration/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Config struct {
4141
pollInterval int
4242
Working chan bool
4343
validExtensions []string
44+
timeout int
4445
}
4546

4647
func GetConfig(flagParser interfaces.IConfigFlags) (*Config, error) {
@@ -131,6 +132,7 @@ func buildConfig(flags interfaces.ConfigFlags) (*Config, error) {
131132
pollInterval: *flags.PollInterval,
132133
Working: make(chan bool, 1),
133134
validExtensions: extensions,
135+
timeout: *flags.Timeout,
134136
}, nil
135137
}
136138

@@ -210,6 +212,10 @@ func (config *Config) GetValidExtensions() []string {
210212
return config.validExtensions
211213
}
212214

215+
func (config *Config) GetTimeout() int {
216+
return config.timeout
217+
}
218+
213219
func buildSecretsMap(secretsFile string, repoRootPath string) (map[string]string, error) {
214220
var file = secretsFile
215221
if _, err := os.Stat(file); os.IsNotExist(err) {

configuration/config_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func getConfigFlagsFor(
111111
AllowDeletes: &ad,
112112
PollInterval: &pi,
113113
ValidExtensions: &ie,
114+
Timeout: &ti,
114115
}
115116

116117
return configFlags

configuration/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func (flags *ConfigFlagsParser) Parse() interfaces.ConfigFlags {
3131
flags.Flags.AllowDeletes = flag.Bool("allow-deletes", false, "Show Gonsul issue deletes? (If not, nothing will be done and a report on conflicting deletes will be shown) (Default false)")
3232
flags.Flags.PollInterval = flag.Int("poll-interval", 60, "The number of seconds for the repository polling interval")
3333
flags.Flags.ValidExtensions = flag.String("input-ext", "json,txt,ini", "A comma separated list of file extensions valid as input")
34+
flags.Flags.Timeout = flag.Int("timeout", 5, "The number of seconds for the client to wait for a response from Consul")
3435

3536
// Parse our command line flags
3637
flag.Parse()

importer/importer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func Start(localData map[string]string, conf *configuration.Config, log *errorut
2929
// create a Client
3030
// A Client is an HTTP client
3131
client := &http.Client{
32-
Timeout: time.Second * 5,
32+
Timeout: time.Second * time.Duration(conf.GetTimeout()),
3333
}
3434

3535
// Populate our Consul live data

interfaces/configurations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type ConfigFlags struct {
1818
AllowDeletes *bool
1919
PollInterval *int
2020
ValidExtensions *string
21+
Timeout *int
2122
}
2223

2324
type IConfigFlags interface {

0 commit comments

Comments
 (0)