-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.go
134 lines (123 loc) · 4.41 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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package monitor
import (
"io/ioutil"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)
// Config contains the parameters for Monitor
type Config struct {
Filename string `yaml:"filename,omitempty"`
URL string `yaml:"url,omitempty"`
MaxSourceFps int `yaml:"maxSourceFps,omitempty"`
MaxOutputFps int `yaml:"maxOutputFps,omitempty"`
Quality int `yaml:"quality,omitempty"`
StaleTimeout int `yaml:"staleTimeout,omitempty"`
StaleMaxRetry int `yaml:"staleMaxRetry,omitempty"`
BufferSeconds int `yaml:"bufferSeconds,omitempty"`
MotionFilename string `yaml:"motion,omitempty"`
TensorFilename string `yaml:"tensor,omitempty"`
CaffeFilename string `yaml:"caffe,omitempty"`
FaceFilename string `yaml:"face,omitempty"`
NotifyRxFilename string `yaml:"notifyRx,omitempty"`
AlertFilename string `yaml:"alert,omitempty"`
RecordFilename string `yaml:"record,omitempty"`
ContinuousFilename string `yaml:"continuous,omitempty"`
}
// NewConfig creates a new Config
func NewConfig(configPath string) *Config {
c := &Config{}
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
}
// RecordConfig contains the parameters for record settings
type RecordConfig struct {
RecordObjects bool `yaml:"recordObjects,omitempty"`
MaxPreSec int `yaml:"maxPreSec,omitempty"`
TimeoutSec int `yaml:"timeoutSec,omitempty"`
MaxSec int `yaml:"maxSec,omitempty"`
DeleteAfterHours int `yaml:"deleteAfterHours,omitempty"`
DeleteAfterGB int `yaml:"deleteAfterGB,omitempty"`
Codec string `yaml:"codec,omitempty"`
FileType string `yaml:"fileType,omitempty"`
BufferSeconds int `yaml:"bufferSeconds,omitempty"`
PortableOnly bool `yaml:"portableOnly,omitempty"`
}
// NewRecordConfig creates a new RecordConfig
func NewRecordConfig(configPath string) *RecordConfig {
c := &RecordConfig{}
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
}
// ContinuousConfig contains the parameters for record settings
type ContinuousConfig struct {
TimeoutSec int `yaml:"timeoutSec,omitempty"`
MaxSec int `yaml:"maxSec,omitempty"`
DeleteAfterHours int `yaml:"deleteAfterHours,omitempty"`
DeleteAfterGB int `yaml:"deleteAfterGB,omitempty"`
Codec string `yaml:"codec,omitempty"`
FileType string `yaml:"fileType,omitempty"`
BufferSeconds int `yaml:"bufferSeconds,omitempty"`
PortableOnly bool `yaml:"portableOnly,omitempty"`
}
// NewContinuousConfig creates a new ContinuousConfig
func NewContinuousConfig(configPath string) *ContinuousConfig {
c := &ContinuousConfig{}
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
}
// AlertConfig contains the parameters for alert notification settings
type AlertConfig struct {
IntervalMinutes int `yaml:"intervalMinutes,omitempty"`
MaxImagesPerInterval int `yaml:"maxImagesPerInterval,omitempty"`
MaxSendAttachmentsPerHour int `yaml:"maxSendAttachmentsPerHour,omitempty"`
SaveQuality int `yaml:"saveQuality,omitempty"`
SaveOriginal bool `yaml:"saveOriginal,omitempty"`
SaveHighlighted bool `yaml:"saveHighlighted,omitempty"`
SaveObjectsCount int `yaml:"saveObjectsCount,omitempty"`
SaveFacesCount int `yaml:"saveFacesCount,omitempty"`
TextAttachments bool `yaml:"textAttachments,omitempty"`
DeleteAfterHours int `yaml:"deleteAfterHours,omitempty"`
DeleteAfterGB int `yaml:"deleteAfterGB,omitempty"`
}
// NewAlertConfig creates a new AlertConfig
func NewAlertConfig(configPath string) *AlertConfig {
c := &AlertConfig{}
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
}