-
Notifications
You must be signed in to change notification settings - Fork 2
/
driver_options.go
60 lines (49 loc) · 1.36 KB
/
driver_options.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
package fireboltgosdk
type driverOption func(d *FireboltDriver)
// WithEngineUrl defines engine url for the driver
func WithEngineUrl(engineUrl string) driverOption {
return func(d *FireboltDriver) {
d.engineUrl = engineUrl
}
}
// WithDatabaseName defines database name for the driver
func WithDatabaseName(databaseName string) driverOption {
return func(d *FireboltDriver) {
if d.cachedParams == nil {
d.cachedParams = map[string]string{}
}
d.cachedParams["database"] = databaseName
}
}
// WithClientParams defines client parameters for the driver
func WithClientParams(accountID string, token string, userAgent string) driverOption {
return func(d *FireboltDriver) {
if d.cachedParams == nil {
d.cachedParams = map[string]string{}
}
// Put account_id in cachedParams for it to work both with engines v1 and v2
d.cachedParams["account_id"] = accountID
cl := &ClientImpl{
ConnectedToSystemEngine: true,
}
cl.UserAgent = userAgent
cl.parameterGetter = cl.getQueryParams
cl.accessTokenGetter = func() (string, error) {
return token, nil
}
d.client = cl
}
}
// FireboltConnectorWithOptions builds a custom connector
func FireboltConnectorWithOptions(opts ...driverOption) *FireboltConnector {
d := &FireboltDriver{}
for _, opt := range opts {
opt(d)
}
return &FireboltConnector{
d.engineUrl,
d.client,
d.cachedParams,
d,
}
}