forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
55 lines (46 loc) · 1.15 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
package udf
import (
"errors"
"fmt"
"time"
"github.com/influxdata/influxdb/toml"
)
type Config struct {
Functions map[string]FunctionConfig `toml:"functions"`
}
type FunctionConfig struct {
// General config
Timeout toml.Duration `toml:"timeout"`
// Config for connecting to domain socket
Socket string `toml:"socket"`
// Config for creating process
Prog string `toml:"prog"`
Args []string `toml:"args"`
Env map[string]string `toml:"env"`
}
func NewConfig() Config {
return Config{}
}
func (c Config) Validate() error {
for name, fc := range c.Functions {
err := fc.Validate()
if err != nil {
return fmt.Errorf("UDF %s: %s", name, err.Error())
}
}
return nil
}
func (c FunctionConfig) Validate() error {
if time.Duration(c.Timeout) <= time.Millisecond {
return fmt.Errorf("timeout is too small: %s", c.Timeout)
}
// We have socket config ensure the process config is empty
if c.Socket != "" {
if c.Prog != "" || len(c.Args) != 0 || len(c.Env) != 0 {
return errors.New("both socket and process config provided")
}
} else if c.Prog == "" {
return errors.New("must set either prog or socket")
}
return nil
}