-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
72 lines (56 loc) · 1.88 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package consul
import (
"time"
"github.com/hashicorp/consul/api"
"gopkg.in/h2non/gentleman-retry.v2"
)
// Scheme represents the URI scheme used by default.
var Scheme = "http"
// DefaultConfig provides a custom
var DefaultConfig = api.DefaultConfig
// CacheTTL stores the default Consul catalog refresh cycle TTL.
// Default to 10 minutes.
var CacheTTL = 10 * time.Minute
// Config represents the plugin supported settings.
type Config struct {
// Retry enables/disables HTTP request retry policy. Defaults to true.
Retry bool
// Cache enables/disables the Consul catalog internal cache
// avoiding recurrent request to Consul server.
Cache bool
// Service stores the Consul's service name identifier. E.g: web.
Service string
// Tag stores the optional Consul's service tag to use when asking to Consul server.
Tag string
// Scheme stores the default HTTP URI scheme to be used when asking to Consul server.
// Defaults to: http.
Scheme string
// Retrier stores the retry strategy to be used.
// Defaults to: ContanstBackOff with max 3 retries.
Retrier retry.Retrier
// CacheTTL stores the max Consul catalog cache TTL.
CacheTTL time.Duration
// Client stores the official Consul client Config instance.
Client *api.Config
// Query stores the official Consul client query options when asking to Consul server.
Query *api.QueryOptions
}
// NewConfig creates a new plugin with default settings and
// custom Consul server URL and service name.
func NewConfig(server, service string) *Config {
config := api.DefaultConfig()
config.Address = server
return &Config{
Retry: true,
Cache: true,
Service: service,
Client: config,
Scheme: Scheme,
CacheTTL: CacheTTL,
Retrier: DefaultRetrier,
}
}
// NewBasicConfig creates a new basic default config with the given Consul server hostname.
func NewBasicConfig(server string) *Config {
return NewConfig(server, "")
}