Skip to content

Commit

Permalink
Merge pull request #4 from coretech/increase_timeout
Browse files Browse the repository at this point in the history
Add ability to provide http timeout for client via CLI option
  • Loading branch information
eduardev committed Jun 25, 2019
2 parents cd57e91 + 0f46c15 commit 57c99ce
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,15 @@ This is the number of seconds you want Gonsul to wait between checks on the repo
This is the file extensions that Gonsul should consider as inputs to populate our Consul. Please set each extension
without the dot, and separate each extension with a comma.


### `--timeout`
> `require:` **no**
> `default:` **5**
> `example:` **`--timeout=20`**
The number of seconds for the client to wait for a response from Consul


## Gonsul Exit Codes
Whenever an error occurs, and Gonsul exits with a code other than 0, we try to return a meaningful code, such as:

Expand Down
6 changes: 6 additions & 0 deletions configuration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Config struct {
pollInterval int
Working chan bool
validExtensions []string
timeout int
}

func GetConfig(flagParser interfaces.IConfigFlags) (*Config, error) {
Expand Down Expand Up @@ -131,6 +132,7 @@ func buildConfig(flags interfaces.ConfigFlags) (*Config, error) {
pollInterval: *flags.PollInterval,
Working: make(chan bool, 1),
validExtensions: extensions,
timeout: *flags.Timeout,
}, nil
}

Expand Down Expand Up @@ -210,6 +212,10 @@ func (config *Config) GetValidExtensions() []string {
return config.validExtensions
}

func (config *Config) GetTimeout() int {
return config.timeout
}

func buildSecretsMap(secretsFile string, repoRootPath string) (map[string]string, error) {
var file = secretsFile
if _, err := os.Stat(file); os.IsNotExist(err) {
Expand Down
1 change: 1 addition & 0 deletions configuration/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func getConfigFlagsFor(
AllowDeletes: &ad,
PollInterval: &pi,
ValidExtensions: &ie,
Timeout: &ti,
}

return configFlags
Expand Down
1 change: 1 addition & 0 deletions configuration/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (flags *ConfigFlagsParser) Parse() interfaces.ConfigFlags {
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)")
flags.Flags.PollInterval = flag.Int("poll-interval", 60, "The number of seconds for the repository polling interval")
flags.Flags.ValidExtensions = flag.String("input-ext", "json,txt,ini", "A comma separated list of file extensions valid as input")
flags.Flags.Timeout = flag.Int("timeout", 5, "The number of seconds for the client to wait for a response from Consul")

// Parse our command line flags
flag.Parse()
Expand Down
2 changes: 1 addition & 1 deletion importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Start(localData map[string]string, conf *configuration.Config, log *errorut
// create a Client
// A Client is an HTTP client
client := &http.Client{
Timeout: time.Second * 5,
Timeout: time.Second * time.Duration(conf.GetTimeout()),
}

// Populate our Consul live data
Expand Down
1 change: 1 addition & 0 deletions interfaces/configurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ConfigFlags struct {
AllowDeletes *bool
PollInterval *int
ValidExtensions *string
Timeout *int
}

type IConfigFlags interface {
Expand Down

0 comments on commit 57c99ce

Please sign in to comment.