/
cliInit.go
106 lines (89 loc) · 2.1 KB
/
cliInit.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package fe26
import (
"os"
"strconv"
log "github.com/sirupsen/logrus"
"flag"
"github.com/AndresBott/Fe26/pkg/f"
"fmt"
)
func preStartChecks () {
// Read Cli Parameters
cliDocRoot := flag.String("root", "", "set the document root (ENV: FE26_ROOT) ")
cliLogLevel := flag.String("loglevel", "info", "set the log level [debug|info|warn|error] (ENV: FE26_LOGLEVEL) ")
cliIp := flag.String("ip", Config.ip, "what IP to listen to, use '0.0.0.0' for all (ENV: FE26_IP)")
cliPort := flag.Int("port", Config.port, "what port to listen to (ENV: FE26_PORT)")
boolPtr := flag.Bool("v", false, "print fe26 version")
flag.Parse()
if *boolPtr {
fmt.Println(Fe26Version)
os.Exit(0)
}
setDocumentRoot(*cliDocRoot)
setPort(*cliPort)
setIp(*cliIp)
setLogLevel(*cliLogLevel)
log.Info("Starting FE26")
log.Info("{" +
"root: \""+Config.docRoot+"\", " +
"ip: "+Config.ip+", " +
"port: "+strconv.Itoa(Config.port)+", " +
"log-level: \""+log.GetLevel().String()+"\", " +
"}")
}
func setIp(cliIpt string){
envIp := os.Getenv("FE26_IP")
ip := ""
if envIp != ""{
ip = envIp
}else if cliIpt != ""{
ip = cliIpt
}
Config.ip = ip
}
func setDocumentRoot(cliDocRoot string){
envDocRoot := os.Getenv("FE26_ROOT")
docRoot := ""
if envDocRoot != ""{
docRoot = envDocRoot
}else if cliDocRoot != ""{
docRoot = cliDocRoot
}else {
docRoot = "./"
}
docRoot,err:= f.GetAbsPathDir(docRoot)
if err != nil {
log.Fatal(err)
}
Config.docRoot = docRoot
}
func setPort(cliPort int) {
envPort, _ := strconv.Atoi(os.Getenv("FE26_PORT"))
port := 0
if envPort != 0{
port = envPort
}else if cliPort != 0{
port = cliPort
}
Config.port = port
}
func setLogLevel(cliLogLevel string){
envLogLevel := os.Getenv("FE26_LOGLEVEL")
logLevel := ""
if envLogLevel != ""{
logLevel = envLogLevel
}else if cliLogLevel != ""{
logLevel = cliLogLevel
}else {
logLevel = "info"
}
if logLevel == "info"{
log.SetLevel(log.InfoLevel)
} else if logLevel == "debug"{
log.SetLevel(log.DebugLevel)
} else if logLevel == "warn"{
log.SetLevel(log.WarnLevel)
} else if logLevel == "error"{
log.SetLevel(log.ErrorLevel)
}
}