This repository has been archived by the owner on Jul 12, 2023. It is now read-only.
/
config.go
70 lines (60 loc) · 1.68 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
package broker
import (
"errors"
"github.com/spf13/cast"
)
type Config struct {
QueueMain string
QueueInvalid string
QueueError string
RepositoryConfig *RepositoryConfig
Validation ValidationMode
}
type RepositoryConfig struct {
Backend string
DynamoDBTLS bool
DynamoDBRegion string
DynamoDBEndpoint string
DynamoDBTable string
}
func (c *Config) Validate() error {
if c.QueueError == "" {
return errors.New("error queue name is undefined")
}
if c.QueueInvalid == "" {
return errors.New("invalid queue name is undefined")
}
if c.QueueMain == "" {
return errors.New("main queue name is undefined")
}
if c.RepositoryConfig == nil || c.RepositoryConfig.Backend == "" {
return errors.New("repository config is undefined")
}
if c.RepositoryConfig.Backend == "dynamodb" && c.RepositoryConfig.DynamoDBTable == "" {
return errors.New("repository config is missing details")
}
return nil
}
// ValidationMode determines the type of message validation that the client
// is going to perform when new messages are received.
type ValidationMode int
const (
// Messages are rejected if invalid, validation issues will be logged.
ValidationModeStrict ValidationMode = iota
// Messages will not be rejected but the validation issues will be logged.
ValidationModeWarnings
// Message validator is disabled.
ValidationModeDisabled
)
func (c *Config) SetValidationMode(mode string) {
if enabled, err := cast.ToBoolE(mode); err == nil && !enabled {
c.Validation = ValidationModeDisabled
return
}
if mode == "warnings" {
c.Validation = ValidationModeWarnings
return
}
// Our default is the strict mode.
c.Validation = ValidationModeStrict
}