-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.go
50 lines (40 loc) · 1.4 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
package async_webhook
import (
"time"
"github.com/code-payments/code-server/pkg/config"
"github.com/code-payments/code-server/pkg/config/env"
"github.com/code-payments/code-server/pkg/config/memory"
"github.com/code-payments/code-server/pkg/config/wrapper"
)
const (
envConfigPrefix = "WEBHOOK_SERVICE_"
WorkerBatchSizeConfigEnvName = envConfigPrefix + "WORKER_BATCH_SIZE"
defaultWorkerBatchSize = 250
WebhookTimeoutConfigEnvName = envConfigPrefix + "WEBHOOK_TIMEOUT"
defaultWebhookTimeout = 3 * time.Second
)
type conf struct {
workerBatchSize config.Uint64
webhookTimeout config.Duration
}
// ConfigProvider defines how config values are pulled
type ConfigProvider func() *conf
// WithEnvConfigs returns configuration pulled from environment variables
func WithEnvConfigs() ConfigProvider {
return func() *conf {
return &conf{
workerBatchSize: env.NewUint64Config(WorkerBatchSizeConfigEnvName, defaultWorkerBatchSize),
webhookTimeout: env.NewDurationConfig(WebhookTimeoutConfigEnvName, defaultWebhookTimeout),
}
}
}
type testOverrides struct {
}
func withManualTestOverrides(overrides *testOverrides) ConfigProvider {
return func() *conf {
return &conf{
workerBatchSize: wrapper.NewUint64Config(memory.NewConfig(defaultWorkerBatchSize), defaultWorkerBatchSize),
webhookTimeout: wrapper.NewDurationConfig(memory.NewConfig(defaultWebhookTimeout), defaultWebhookTimeout),
}
}
}