-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.go
75 lines (63 loc) · 1.34 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"log"
"net/url"
"os"
"os/exec"
"path/filepath"
)
//
var Settings struct {
Debugger bool
Verbose bool
Mode string
Addr string
Port int
Secure bool
Server string
Powered string
Version string
Program struct {
Name string
Folder string
Full string
Data string
Config string
}
Docs *url.URL
}
//
const MAJOR = "0.1"
// DO NOT UPDATE. This is populated by the build. See the Makefile.
var VERSION = "0"
//
func init() {
Settings.Program.Full = os.Args[0]
Settings.Program.Name = filepath.Base(Settings.Program.Full)
if dir, _ := filepath.Split(Settings.Program.Full); dir == "" {
if path, err := exec.LookPath(Settings.Program.Full); err != nil {
log.Println(err)
} else {
Settings.Program.Folder = filepath.Base(path)
}
} else if ln, err := filepath.EvalSymlinks(Settings.Program.Full); err != nil {
log.Println(err)
} else {
if dir, err := filepath.Abs(filepath.Dir(ln)); err != nil {
log.Println(err)
} else {
Settings.Program.Folder = dir
}
}
data := os.Getenv("DATA")
if data == "" {
data = "data"
}
Settings.Program.Data = filepath.Join(Settings.Program.Folder, data)
config := os.Getenv("CONFIG")
if config == "" {
Settings.Program.Config = filepath.Join(Settings.Program.Folder, "config/app.yaml")
} else {
Settings.Program.Config = config
}
}