forked from katzenpost/catchat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
50 lines (43 loc) · 1.04 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
package main
import (
"log"
"os"
"github.com/BurntSushi/toml"
)
// Config holds catchat's config settings
type Config struct {
Theme string
Style string
PositionX int
PositionY int
Width int
Height int
FirstRun bool
}
// LoadConfig returns the current config as a Config struct
func LoadConfig(configFile string) Config {
_, err := os.Stat(configFile)
if err != nil {
SaveConfig(configFile, Config{
Theme: "Material",
Style: "Dark",
FirstRun: true,
})
//log.Fatal("Config file is missing, but a template was created for you! Please edit ", configFile)
}
var config Config
if _, err := toml.DecodeFile(configFile, &config); err != nil {
log.Fatal("Could not decode config file: ", err)
}
return config
}
// SaveConfig stores the current config
func SaveConfig(configFile string, config Config) {
f, err := os.Create(configFile)
if err != nil {
log.Fatal("Could not open config file: ", err)
}
if err := toml.NewEncoder(f).Encode(config); err != nil {
log.Fatal("Could not encode config: ", err)
}
}