-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
63 lines (57 loc) · 1.21 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
package main
import (
"encoding/json"
"os"
)
type Configuration struct {
Username string
Wallpaper string
DPI int
Label struct {
Color string
Margin int
UsernameText string
PasswordText string
}
Entry struct {
WidthChars int
TextAlignement float32
TextColor string
BackgroundColor string
CaretColor string
}
Box struct {
MarginLeft int
MarginTop int
MarginBottom int
MarginRight int
}
}
func loadConfig(fpath string) (config Configuration, err error) {
// default configuration
config.Username = ""
config.Wallpaper = ""
config.DPI = 96
config.Label.Color = "#000000"
config.Label.Margin = 0
config.Label.UsernameText = "username:"
config.Label.PasswordText = "password:"
config.Entry.WidthChars = 10
config.Entry.TextColor = "#000000"
config.Entry.BackgroundColor = "#ffffff"
config.Entry.CaretColor = "#000000"
config.Entry.TextAlignement = 0.5
config.Box.MarginTop = 0
config.Box.MarginBottom = 0
config.Box.MarginLeft = 0
config.Box.MarginRight = 0
// loading conf file
file, err := os.Open(fpath)
if err != nil {
return
}
defer file.Close()
decoder := json.NewDecoder(file)
err = decoder.Decode(&config)
return
}