-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
80 lines (67 loc) · 1.48 KB
/
config.go
File metadata and controls
80 lines (67 loc) · 1.48 KB
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
71
72
73
74
75
76
77
78
79
80
package main
import (
"os"
"time"
"gopkg.in/yaml.v3"
)
type Config struct {
Logging LogConfig `yaml:"logging"`
Triggers []TriggerConfig `yaml:"triggers"`
}
type LogConfig struct {
Output string `yaml:"output"`
}
type TriggerConfig struct {
Name string `yaml:"name"`
PubSub PubSubConfig `yaml:"pubsub"`
Run RunConfig `yaml:"run"`
}
type PubSubConfig struct {
Project string `yaml:"project"`
Subscription string `yaml:"subscription"`
}
type RunConfig struct {
Exec string `yaml:"exec"`
Args ArgsConfig `yaml:"args"`
Timeout time.Duration `yaml:"timeout"`
Concurrency int `yaml:"concurrency"`
}
type ArgsConfig struct {
Expression string `yaml:"expression"`
}
func loadConfig(file string) Config {
var config Config
// read file and unmarshal it
data, err := os.ReadFile(file)
if err != nil {
panic(err)
}
err = yaml.Unmarshal(data, &config)
if err != nil {
panic(err)
}
return config
}
func (c *RunConfig) UnmarshalYAML(value *yaml.Node) error {
var tmp struct {
Exec string `yaml:"exec"`
Args ArgsConfig `yaml:"args"`
Timeout string `yaml:"timeout"`
Concurrency int `yaml:"concurrency"`
}
err := value.Decode(&tmp)
if err != nil {
return err
}
timeout, err := time.ParseDuration(tmp.Timeout)
if err != nil {
return err
}
*c = RunConfig{
Exec: tmp.Exec,
Args: tmp.Args,
Timeout: timeout,
Concurrency: tmp.Concurrency,
}
return nil
}