-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
37 lines (31 loc) · 931 Bytes
/
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
package main
import (
"io/ioutil"
"gopkg.in/yaml.v3"
)
// EmailDeduperConfig maps the config values to a Go struct
type EmailDeduperConfig struct {
GenerateEmailCount int `yaml:"GENERATE_EMAIL_COUNT"`
DuplicatePercentage float32 `yaml:"DUPLICATE_PERCENTAGE"`
}
// CreateFromFile populates a new Config with data from a YAML file
func CreateFromFile(config *EmailDeduperConfig, fname string) error {
data, err := ioutil.ReadFile(fname)
if err != nil {
return err
}
return yaml.Unmarshal(data, config)
}
// LoadConfigFromFile loads a EmailDeduperConfig from the file specified by path
func LoadConfigFromFile(path string) (EmailDeduperConfig, error) {
config := EmailDeduperConfig{}
err := CreateFromFile(&config, path)
if err != nil {
return config, err
}
return config, err
}
// LoadConfig loads the config file
func LoadConfig() (EmailDeduperConfig, error) {
return LoadConfigFromFile("config.yml")
}