forked from rai-project/registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.go
55 lines (50 loc) · 1.39 KB
/
store.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
package registry
import (
"context"
"github.com/c3sr/libkv"
"github.com/c3sr/libkv/store"
"github.com/c3sr/libkv/store/consul"
"github.com/c3sr/libkv/store/mock"
)
type Store interface {
store.Store
}
func New(opts ...Option) (Store, error) {
options := Options{
Provider: Config.Provider,
Endpoints: cleanupEndpoints(Config.Endpoints),
Username: Config.Username,
Password: Config.Password,
Timeout: Config.Timeout,
TLSConfig: nil,
PersistConnection: true,
Context: context.Background(),
}
if Config.HeaderTimeoutPerRequest != 0 {
HeaderTimeoutPerRequest(Config.HeaderTimeoutPerRequest)(&options)
}
if Config.Certificate != "" {
TLSCertificate(Config.Certificate)(&options)
}
AutoSync(Config.AutoSync)(&options)
for _, o := range opts {
o(&options)
}
storeConfig := &store.Config{
ClientTLS: &store.ClientTLSConfig{},
ConnectionTimeout: options.Timeout,
Username: options.Username,
Password: options.Password,
TLS: options.TLSConfig,
Bucket: options.Bucket,
PersistConnection: options.PersistConnection,
Context: options.Context,
}
if options.Provider == store.Backend("mock") {
return mock.New(options.Endpoints, storeConfig)
}
return libkv.NewStore(options.Provider, options.Endpoints, storeConfig)
}
func init() {
consul.Register()
}