-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
54 lines (43 loc) · 1.28 KB
/
config.go
File metadata and controls
54 lines (43 loc) · 1.28 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
package redeye
import (
"fmt"
"encoding/json"
"io/ioutil"
"net/http"
)
type Configuration struct {
HTTPAddr string `json:"addr"` // http address and port
HTMLPath string `json:"basepath"` // html basepath
MQTTBroker string `json:"broker"` // MQTT Broker
VideoDevice int `json:video-device` // Capture device
Image string `json:image` // Single image
Video string `json:video`
CascadeFile string `json:cascade-file`
Pipeline string `json:"pipeline"`
WaitTime int `json"wait-time"`
ListFilters bool `json:"list-filters"` // List filters
ID string `json:"id"`
Thumb string `json:"thumb"`
Debug bool `json:"debug"`
}
var (
Config *Configuration = &Configuration{}
)
func GetConfig() *Configuration {
return Config
}
func (c *Configuration) Save(path string) (err error) {
buf, err := json.Marshal(c)
if err != nil {
return fmt.Errorf("Config Save [%s] failed json.Marshal config [%w]", path, err)
}
err = ioutil.WriteFile(path, buf, 0644)
if err != nil {
return fmt.Errorf("Config Save [%s] failed to save file: [%w]", path, err)
}
return err
}
// ServeHTTP provides the Web service for the configuration module
func (c Configuration) ServeHTTP(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(c)
}