externalize timeout value

This commit is contained in:
Kumar Krishna 2016-11-14 13:27:25 -08:00
parent a715282c00
commit 8905233375
2 changed files with 3 additions and 3 deletions

View file

@ -57,7 +57,7 @@ func main() {
}
//Create new configuration with default transport layer
config, err := realis.NewDefaultConfig(*url)
config, err := realis.NewDefaultConfig(*url, 10000)
if err != nil {
fmt.Println(err)
os.Exit(1)

View file

@ -69,7 +69,7 @@ func NewClient(config RealisConfig) Realis {
}
// Create a default configuration of the transport layer, requires a URL to test connection with.
func NewDefaultConfig(url string) (RealisConfig, error) {
func NewDefaultConfig(url string, timeoutms int) (RealisConfig, error) {
jar, err := cookiejar.New(nil)
if err != nil {
@ -78,7 +78,7 @@ func NewDefaultConfig(url string) (RealisConfig, error) {
//Custom client to timeout after 10 seconds to avoid hanging
trans, err := thrift.NewTHttpPostClientWithOptions(url+"/api",
thrift.THttpClientOptions{Client: &http.Client{Timeout: time.Second * 10, Jar: jar}})
thrift.THttpClientOptions{Client: &http.Client{Timeout: time.Millisecond * time.Duration(timeoutms), Jar: jar}})
if err != nil {
return RealisConfig{}, errors.Wrap(err, "Error creating transport")