github.com/m-lab/locate@v0.17.6/limits/config.go (about) 1 package limits 2 3 import ( 4 "os" 5 "time" 6 7 "gopkg.in/yaml.v2" 8 ) 9 10 // AgentConfig holds the limit configuration for a user agent. 11 type AgentConfig struct { 12 Agent string `yaml:"agent"` 13 Schedule string `yaml:"schedule"` 14 Duration time.Duration `yaml:"duration"` 15 } 16 17 // Config holds the limit configuration for all user agents. 18 type Config []AgentConfig 19 20 // ParseConfig interprets the configuration file and returns the set 21 // of agent limits. 22 func ParseConfig(path string) (Agents, error) { 23 f, err := os.Open(path) 24 if err != nil { 25 return nil, err 26 } 27 defer f.Close() 28 29 config := &Config{} 30 decoder := yaml.NewDecoder(f) 31 err = decoder.Decode(config) 32 33 lmts := make(Agents) 34 for _, l := range *config { 35 lmts[l.Agent] = NewCron(l.Schedule, l.Duration) 36 } 37 return lmts, err 38 }