-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
51 lines (45 loc) · 947 Bytes
/
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
package main
import (
"encoding/json"
"io/ioutil"
"log"
"time"
)
type config struct {
Mattermosttoken string
ConsumerKey string
ConsumerSecret string
AccessToken string
AccessTokenSecret string
Rate int
LastCheck time.Time
Nicklist string
}
func (c *config) load(f string) {
file, err := ioutil.ReadFile(f)
if err != nil {
log.Fatal("Could not load: ", err)
}
err = json.Unmarshal(file, c)
if err != nil {
log.Fatal("Could not parse: ", err)
}
file, err = ioutil.ReadFile(conf.Nicklist)
if err != nil {
log.Fatal("Could not load: ", err)
}
err = json.Unmarshal(file, &Nicklist)
if err != nil {
log.Fatal("Could not parse: ", err)
}
}
func (c *config) save(f string) {
b, err := json.MarshalIndent(c, "", " ")
if err != nil {
log.Fatal("Could not marshal:", err)
}
err = ioutil.WriteFile(f, b, 664)
if err != nil {
log.Fatal("Could not save:", err)
}
}