-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
55 lines (51 loc) · 1.07 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 (
"errors"
"fmt"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
)
type Config struct {
SocketPort uint16
APIPort uint16
LpacExeName string
LpacPath string
}
var CFG Config
func InitConfig() error {
switch runtime.GOOS {
case "windows":
CFG.LpacExeName = "lpac.exe"
default:
CFG.LpacExeName = "lpac"
}
pwd, err := os.Getwd()
if err != nil {
return errors.New(fmt.Sprint("Failed to get pwd: ", err))
}
CFG.LpacPath = filepath.Join(pwd, CFG.LpacExeName)
socketPort := strings.TrimSpace(os.Getenv("SOCKET_PORT"))
if socketPort == "" {
CFG.SocketPort = 1888
} else {
sPort, err := strconv.ParseUint(socketPort, 16, 16)
if err != nil {
return errors.New("Failed to parse SOCKET_PORT: " + err.Error())
}
CFG.SocketPort = uint16(sPort)
}
apiPort := strings.TrimSpace(os.Getenv("API_PORT"))
if apiPort == "" {
CFG.APIPort = 8008
} else {
aPort, err := strconv.ParseUint(apiPort, 16, 16)
if err != nil {
return errors.New("Failed to parse API_PORT: " + err.Error())
}
CFG.APIPort = uint16(aPort)
}
return nil
}