-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
55 lines (47 loc) · 1.06 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
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"path/filepath"
"runtime"
)
// Configuration record the config.json data
type Configuration struct {
Admin administrator `json:"admin"`
RemoteAddr string `json:"remoteAddr"`
RemotePort string `json:"remotePort"`
}
type administrator struct {
Username string `json:"username"`
Password string `json:"password"`
}
// UserHomeDir return $HOME directory
func UserHomeDir() string {
if runtime.GOOS == "windows" {
home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
if home == "" {
home = os.Getenv("USERPROFILE")
}
return home
}
return os.Getenv("HOME")
}
// DefaultCtrDir return the config.json file's filepath
func DefaultCtrDir() string {
return filepath.Join(UserHomeDir(), ".gosuvctr")
}
func readConfig(configPath string) (c Configuration, err error) {
c.RemoteAddr = "127.0.0.1"
c.RemotePort = "11313"
data, err := ioutil.ReadFile(configPath)
if err != nil {
log.Fatal(err)
}
err = json.Unmarshal(data, &c)
if err != nil {
log.Fatal(err)
}
return
}