forked from creamlike1024/EasyLPAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
50 lines (44 loc) · 984 Bytes
/
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
package main
import (
"fmt"
"os"
"path/filepath"
"runtime"
"time"
)
type Config struct {
LpacDir 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)
switch platform := runtime.GOOS; platform {
case "windows":
ConfigInstance.EXEName = "lpac.exe"
ConfigInstance.LpacDir = exeDir
ConfigInstance.LogDir = filepath.Join(exeDir, "log")
default:
ConfigInstance.EXEName = "lpac"
ConfigInstance.LpacDir = exeDir
ConfigInstance.LogDir = filepath.Join("/tmp", "EasyLPAC-log")
}
ConfigInstance.AutoMode = true
ConfigInstance.LogFilename = fmt.Sprintf("lpac-%s.txt", time.Now().Format("20060102-150405"))
return nil
}