-
Notifications
You must be signed in to change notification settings - Fork 22
/
enricher_config.go
75 lines (62 loc) · 1.86 KB
/
enricher_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
package enriching
import (
"go.uber.org/zap"
"time"
)
type (
enrichmentConfig struct {
// CloudSaveURL is the URL to call the Cloud Save service.
cloudSave cloudSaveConfig
// WebhookUrls contains the necessary parameters to call a webhook for a given game.
// The key should be the game tenantID.
webhookUrls map[string]string
// WebhookTimeout is the timeout for the webhook call.
webhookTimeout time.Duration
}
cloudSaveConfig struct {
// Enabled indicates whether the Cloud Save service should be used for enrichment.
enabled map[string]bool
// URL is the URL to call the Cloud Save service.
url string
}
)
func newDefaultEnrichConfig() enrichmentConfig {
return enrichmentConfig{
cloudSave: cloudSaveConfig{
enabled: map[string]bool{},
},
webhookUrls: map[string]string{},
webhookTimeout: 500 * time.Millisecond,
}
}
type EnricherOptions func(*enricherImpl)
// WithCloudSaveUrl sets the Cloud Save URL.
func WithCloudSaveUrl(url string) EnricherOptions {
return func(impl *enricherImpl) {
impl.config.cloudSave.url = url
}
}
// WithWebhookUrls sets the map of webhook URL for each tenantID.
func WithWebhookUrls(urlsMap map[string]string) EnricherOptions {
return func(impl *enricherImpl) {
impl.config.webhookUrls = urlsMap
}
}
// WithWebhookTimeout sets the webhook timeout.
func WithWebhookTimeout(timeout time.Duration) EnricherOptions {
return func(impl *enricherImpl) {
impl.config.webhookTimeout = timeout
}
}
// WithCloudSaveEnabled sets the map of enabled Cloud Save for each tenantID.
func WithCloudSaveEnabled(enabled map[string]bool) EnricherOptions {
return func(impl *enricherImpl) {
impl.config.cloudSave.enabled = enabled
}
}
// WithLogger sets the logger.
func WithLogger(logger *zap.Logger) EnricherOptions {
return func(impl *enricherImpl) {
impl.logger = logger.With(zap.String("source", "enricher"))
}
}