-
Notifications
You must be signed in to change notification settings - Fork 9
/
config.go
62 lines (52 loc) · 1.71 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
package main
import (
"os"
"gopkg.in/yaml.v2"
)
// Config is the internal representation of the yaml that determines what
// the app listens to an enqueues
type Config struct {
Redis RedisConfig `yaml:"redis"`
AWS AWSConfig `yaml:"aws"`
Queue QueueConfig `yaml:"queue"`
SQS SQSConfig
}
// RedisConfig is a nested config that contains the necessary parameters to
// connect to a redis instance and enqueue workers.
type RedisConfig struct {
Host string `yaml:"host"`
Queue string `yaml:"queue"`
Namespace string `yaml:"namespace"` // optional
Password string `yaml:"password"` // optional
}
// AWSConfig is a nested config that contains the necessary parameters to
// connect to AWS and read from SQS
type AWSConfig struct {
AccessKey string `yaml:"access_key"`
SecretKey string `yaml:"secret_key"`
Region string `yaml:"region"`
}
// QueueConfig is a nested config that gives the SQS queue to listen on
// and a mapping of topics to workeers
type QueueConfig struct {
Name string `yaml:"name"`
Topics map[string]string `yaml:"topics"`
}
// SQSConfig is a nested config meant to be passed directly to the SQS client
type SQSConfig struct {
maxNumberOfMessages int64 `yaml:"max_number_of_messages"`
waitTimeSeconds int64 `yaml:"wait_time_seconds"`
visibilityTimeout int64 `yaml:"visibility_timeout"`
}
// ReadConfig reads from a file with the given name and returns a config or
// an error if the file was unable to be parsed. It does no error checking
// as far as required fields.
func ReadConfig(file string) (*Config, error) {
data, err := os.ReadFile(file)
if err != nil {
return nil, err
}
config := new(Config)
err = yaml.Unmarshal(data, config)
return config, err
}