forked from kuznetsovin/go_tachograph_card
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.go
43 lines (38 loc) · 767 Bytes
/
settings.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
package main
import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
)
type Settings struct {
Server string
Port string
Queue string
UploadDir string
Log string
}
func (settings *Settings) init() error {
setting_json, err := ioutil.ReadFile("setting.json")
if err != nil {
return err
}
if err = json.Unmarshal(setting_json, settings); err != nil {
return err
}
if err := os.MkdirAll(settings.UploadDir, os.ModePerm); err != nil {
return err
}
if _, err := os.Stat(settings.Log); os.IsNotExist(err) {
path := filepath.Dir(settings.Log)
if err := os.MkdirAll(path, os.ModePerm); err != nil {
return err
}
f, err := os.Create(settings.Log)
if err != nil {
return err
}
defer f.Close()
}
return err
}