-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
49 lines (38 loc) · 967 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
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"io/ioutil"
"log"
"os"
"path/filepath"
"gopkg.in/yaml.v3"
)
type Config struct {
ActivityMonitorConfigs []ActivityMonitorConfig `yaml:"activity-monitors"`
}
type ActivityMonitorConfig struct {
MaxActivityTime string `yaml:"max-activity-time"`
InactivityTime string `yaml:"inactivity-time"`
MessageFormat string `yaml:"message-format"`
}
func NewConfig() Config {
return Config{}
}
func (config *Config) readConfig() error {
configPath := os.Getenv("HWORKER_CONFIG")
if configPath == "" {
log.Println("HWORKER_CONFIG was not supplied. Reading from default path.")
ex, err := os.Executable()
if err != nil {
return err
}
exPath := filepath.Dir(ex)
configPath = filepath.Join(exPath, "..", "config.yaml")
}
yfile, err := ioutil.ReadFile(configPath)
if err != nil {
return err
}
err = yaml.Unmarshal(yfile, config)
log.Printf("Successfully read config file from path %s\n", configPath)
return err
}