Skip to content

Commit acc5dac

Browse files
authored
Add http timeout option
1 parent 891efdf commit acc5dac

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

engine/engine.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ func New(resultCache cache.Interface, valueStore indexer.Interface, options ...O
6868
dhMergeURL: dhMergeURL,
6969
dhMetaURL: dhMetaURL,
7070
vsNoNewMH: opts.vsNoNewMH,
71+
httpClient: http.Client{
72+
Timeout: opts.httpClientTimeout,
73+
},
7174
}
7275
}
7376

engine/option.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,28 @@ package engine
33
import (
44
"fmt"
55
"net/url"
6+
"time"
67
)
78

89
const defaultDHBatchSize = 1024
10+
const defaultHttpTimeout = 5 * time.Second
911

1012
// config contains all options for configuring Engine.
1113
type config struct {
12-
cacheOnPut bool
13-
dhBatchSize int
14-
dhstoreURL string
15-
vsNoNewMH bool
14+
cacheOnPut bool
15+
dhBatchSize int
16+
dhstoreURL string
17+
vsNoNewMH bool
18+
httpClientTimeout time.Duration
1619
}
1720

1821
type Option func(*config) error
1922

2023
// getOpts creates a config and applies Options to it.
2124
func getOpts(opts []Option) (config, error) {
2225
cfg := config{
23-
dhBatchSize: defaultDHBatchSize,
26+
dhBatchSize: defaultDHBatchSize,
27+
httpClientTimeout: defaultHttpTimeout,
2428
}
2529

2630
for i, opt := range opts {
@@ -74,3 +78,11 @@ func WithVSNoNewMH(ok bool) Option {
7478
return nil
7579
}
7680
}
81+
82+
// WithHttpClientTimeout sets http timeout for queries to DHStore
83+
func WithHttpClientTimeout(timeout time.Duration) Option {
84+
return func(cfg *config) error {
85+
cfg.httpClientTimeout = timeout
86+
return nil
87+
}
88+
}

0 commit comments

Comments
 (0)