-
Notifications
You must be signed in to change notification settings - Fork 0
/
gouniversal.go
145 lines (109 loc) · 2.88 KB
/
gouniversal.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package main
import (
"bufio"
"fmt"
"os"
"runtime"
"strconv"
"strings"
"time"
//_ "net/http/pprof"
"github.com/dekoch/gouniversal/build"
"github.com/dekoch/gouniversal/module"
"github.com/dekoch/gouniversal/program/global"
"github.com/dekoch/gouniversal/program/lang"
"github.com/dekoch/gouniversal/program/ui"
"github.com/dekoch/gouniversal/shared/console"
"github.com/dekoch/gouniversal/shared/language"
"github.com/dekoch/gouniversal/shared/types"
)
func main() {
err := console.LoadConfig()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
console.Log("App starting...", " ")
console.Log("Build: "+build.BuildTime, " ")
console.Log("Commit: "+build.Commit, " ")
console.Input("")
en := lang.DefaultEn()
global.Lang = language.New("data/lang/program/", en, "en")
if build.UIEnabled {
err = global.UIConfig.LoadConfig()
if err != nil {
console.Log(err, "")
}
}
// UI or console mode
if build.UIEnabled && global.UIConfig.UIEnabled {
// start UI
go ui.StartServer()
} else {
console.Log("UI is disabled", " ")
module.LoadConfig()
}
go consoleInput()
exitApp := false
for exitApp == false {
s := console.GetInput()
if s != "" {
switch s {
case "help":
printHelp()
case "build":
console.Output(build.BuildTime, " ")
case "commit":
console.Output(build.Commit, " ")
case "gover":
console.Output(runtime.Version(), " ")
case "gocpu":
console.Output(strconv.Itoa(runtime.NumCPU()), " ")
case "gonum":
console.Output(strconv.Itoa(runtime.NumGoroutine()), " ")
case "exit":
exitApp = true
default:
console.Output("unrecognized command \""+s+"\"", " ")
console.Output("Type 'help' for a list of available commands.", " ")
}
console.Input("")
}
time.Sleep(100 * time.Millisecond)
}
if build.UIEnabled && global.UIConfig.UIEnabled {
ui.Exit()
}
var em types.ExitMessage
em.Users = ui.GetUserUUIDList()
module.Exit(&em)
console.Log("App ended", " ")
os.Exit(0)
}
func printHelp() {
console.Output("", " ")
console.Output("Command\t\tMeaning", " ")
console.Output("", " ")
console.Output("help\t\tShow this help text", " ")
console.Output("build\t\tReturns the build timestamp.", " ")
console.Output("commit\t\tReturns the commit ID.", " ")
console.Output("gover\t\tReturns the Go tree's version string.", " ")
console.Output("gocpu\t\tReturns the number of logical CPUs usable by the current process.", " ")
console.Output("gonum\t\tReturns the number of goroutines that currently exist.", " ")
console.Output("exit\t\tExit this program", " ")
}
func consoleInput() {
var input string
scanner := bufio.NewScanner(os.Stdin)
for {
if scanner.Scan() {
input = scanner.Text()
if input != "" {
input = strings.Replace(input, "\n", "", -1)
input = strings.Replace(input, "\r", "", -1)
console.Input(input)
}
}
time.Sleep(100 * time.Millisecond)
}
}