-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
84 lines (75 loc) · 2.65 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
73
74
75
76
77
78
79
80
81
82
83
84
package asc
import (
"fmt"
"github.com/viant/dsc"
"strings"
"time"
)
const (
pkColumnKey = "keyColumn"
pkColumnNameKey = "keyColumnName"
inheritIdFromPKKey = "inheritIdFromPK"
generationColumnKey = "generationColumn"
excludedColumnsKey = "excludedColumns"
serverSocketTimeoutKey = "serverSocketTimeout"
connectionTimeoutMsKey = "connectionTimeoutMs"
timeoutMsKey = "timeoutMs"
maxRetriesKey = "maxRetries"
sleepBetweenRetriesMsKey = "sleepBetweenRetriesMs"
namespaceKey = "namespace"
hostKey = "host"
portKey = "port"
scanPctKey = "scanPct"
batchSizeKey = "batchSize"
optimizeLargeScanKey = "optimizeLargeScan"
scanBaseDirectoryKey = "scanBaseDirectory"
)
type config struct {
*dsc.Config
keyColumn string
connectionTimeout time.Duration
timeout time.Duration
serverSocketTimeout time.Duration
scanPct int
maxRetries int
sleepBetweenRetries time.Duration
generationColumn string
namespace string
excludedColumns []string
inheritIdFromPK bool
batchSize int
optimizeLargeScan bool
scanBaseDirectory string
}
func (m *config) getKeyColumn(table string) string {
if keyColumn := m.GetString(table+"."+pkColumnKey, ""); keyColumn != "" {
return keyColumn
}
return m.keyColumn
}
func newConfig(conf *dsc.Config) (*config, error) {
result := &config{
Config: conf,
scanPct: conf.GetInt(scanPctKey, 100),
serverSocketTimeout: conf.GetDuration(serverSocketTimeoutKey, time.Millisecond, 30000*time.Millisecond),
connectionTimeout: conf.GetDuration(connectionTimeoutMsKey, time.Millisecond, 5000*time.Millisecond),
timeout: conf.GetDuration(timeoutMsKey, time.Millisecond, 5000*time.Millisecond),
sleepBetweenRetries: conf.GetDuration(sleepBetweenRetriesMsKey, time.Millisecond, 100*time.Millisecond),
maxRetries: conf.GetInt(maxRetriesKey, 3),
namespace: conf.Get(namespaceKey),
generationColumn: conf.GetString(generationColumnKey, ""),
keyColumn: conf.GetString(pkColumnKey, ""),
inheritIdFromPK: conf.GetBoolean(inheritIdFromPKKey, true),
excludedColumns: strings.Split(conf.Get(excludedColumnsKey), ","),
batchSize: conf.GetInt(batchSizeKey, 256),
optimizeLargeScan: conf.GetBoolean(optimizeLargeScanKey, false),
scanBaseDirectory: conf.GetString(scanBaseDirectoryKey, ""),
}
if result.namespace == "" {
return nil, fmt.Errorf("namespaceKey was empty")
}
if result.keyColumn = conf.GetString(pkColumnKey, ""); result.keyColumn == "" {
result.keyColumn = conf.GetString(pkColumnNameKey, "id")
}
return result, nil
}