/
config.go
42 lines (37 loc) · 1.16 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
package motion
import (
"io/ioutil"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)
// Config contains the parameters for Motion detection
type Config struct {
Skip bool `yaml:"skip,omitempty"`
Padding int `yaml:"padding,omitempty"`
ScaleWidth int `yaml:"scaleWidth,omitempty"`
MinimumPercentage int `yaml:"minPercentage,omitempty"`
MaximumPercentage int `yaml:"maxPercentage,omitempty"`
MaxMotions int `yaml:"maxMotions,omitempty"`
OverloadPercent int `yaml:"overloadPercent,omitempty"`
ThresholdPercent int `yaml:"thresholdPercent,omitempty"`
NoiseReduction int `yaml:"noiseReduction,omitempty"`
HighlightColor string `yaml:"highlightColor,omitempty"`
HighlightThickness int `yaml:"highlightThickness,omitempty"`
}
// NewConfig creates a new Config
func NewConfig(configPath string) *Config {
c := &Config{
MinimumPercentage: -1,
}
yamlFile, err := ioutil.ReadFile(configPath)
if err != nil {
log.Printf("yamlFile.Get err #%v ", err)
return nil
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
log.Printf("Unmarshal: %v", err)
return nil
}
return c
}