-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathconfig.go
61 lines (54 loc) · 1.34 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
package main
import (
"fmt"
"os"
"path/filepath"
"runtime"
"time"
)
const AID_DEFAULT = "A0000005591010FFFFFFFF8900000100"
const AID_5BER = "A0000005591010FFFFFFFF8900050500"
type Config struct {
LpacDir string
LpacAID string
EXEName string
DriverIFID string
DebugHTTP bool
DebugAPDU bool
LogDir string
LogFilename string
LogFile *os.File
AutoMode bool
}
var ConfigInstance Config
func LoadConfig() error {
exePath, err := os.Executable()
if err != nil {
return err
}
exePath, err = filepath.EvalSymlinks(exePath)
if err != nil {
return err
}
exeDir := filepath.Dir(exePath)
ConfigInstance.LpacDir = exeDir
switch platform := runtime.GOOS; platform {
case "windows":
ConfigInstance.EXEName = "lpac.exe"
ConfigInstance.LogDir = filepath.Join(exeDir, "log")
case "linux":
ConfigInstance.EXEName = "lpac"
ConfigInstance.LogDir = filepath.Join("/tmp", "EasyLPAC-log")
_, err = os.Stat(filepath.Join(ConfigInstance.LpacDir, ConfigInstance.EXEName))
if err != nil {
ConfigInstance.LpacDir = "/usr/bin"
}
default:
ConfigInstance.EXEName = "lpac"
ConfigInstance.LogDir = filepath.Join("/tmp", "EasyLPAC-log")
}
ConfigInstance.AutoMode = true
ConfigInstance.LpacAID = AID_DEFAULT
ConfigInstance.LogFilename = fmt.Sprintf("lpac-%s.txt", time.Now().Format("20060102-150405"))
return nil
}