-
Notifications
You must be signed in to change notification settings - Fork 47
/
server.go
94 lines (77 loc) · 1.99 KB
/
server.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
package main
import (
"os"
"path/filepath"
"runtime/debug"
"github.com/urfave/cli"
logger_util "github.com/free5gc/util/logger"
"github.com/free5gc/util/version"
"github.com/free5gc/webconsole/backend/factory"
"github.com/free5gc/webconsole/backend/logger"
"github.com/free5gc/webconsole/backend/webui_service"
)
var WEBUI *webui_service.WebuiApp
func main() {
defer func() {
if p := recover(); p != nil {
// Print stack for panic to log. Fatalf() will let program exit.
logger.MainLog.Fatalf("panic: %v\n%s", p, string(debug.Stack()))
}
}()
app := cli.NewApp()
app.Name = "webui"
app.Usage = "free5GC Web Console"
app.Action = action
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config, c",
Usage: "Load configuration from `FILE`",
},
cli.StringSliceFlag{
Name: "log, l",
Usage: "Output NF log to `FILE`",
},
}
if err := app.Run(os.Args); err != nil {
logger.MainLog.Errorf("WEBUI Run error: %v\n", err)
}
}
func action(cliCtx *cli.Context) error {
tlsKeyLogPath, err := initLogFile(cliCtx.StringSlice("log"))
if err != nil {
return err
}
logger.MainLog.Infoln("WEBUI version: ", version.GetVersion())
cfg, err := factory.ReadConfig(cliCtx.String("config"))
if err != nil {
return err
}
factory.WebuiConfig = cfg
webui, err := webui_service.NewApp(cfg)
if err != nil {
return err
}
WEBUI = webui
webui.Start(tlsKeyLogPath)
return nil
}
func initLogFile(logNfPath []string) (string, error) {
logTlsKeyPath := ""
for _, path := range logNfPath {
if err := logger_util.LogFileHook(logger.Log, path); err != nil {
return "", err
}
if logTlsKeyPath != "" {
continue
}
nfDir, _ := filepath.Split(path)
tmpDir := filepath.Join(nfDir, "key")
if err := os.MkdirAll(tmpDir, 0o775); err != nil {
logger.InitLog.Errorf("Make directory %s failed: %+v", tmpDir, err)
return "", err
}
_, name := filepath.Split(factory.WebuiDefaultTLSKeyLogPath)
logTlsKeyPath = filepath.Join(tmpDir, name)
}
return logTlsKeyPath, nil
}