forked from cdle/sillyGirl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (60 loc) · 1.3 KB
/
main.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
package main
import (
"bufio"
"os"
"runtime"
"time"
"github.com/DeanThompson/ginpprof"
"github.com/beego/beego/v2/core/logs"
"github.com/cdle/sillyGirl/core"
"github.com/cdle/sillyGirl/utils"
)
func main() {
core.Init()
ginpprof.Wrapper(core.Server)
sillyGirl := core.MakeBucket("sillyGirl")
go monitorGoroutine()
port := sillyGirl.GetString("port", "8080")
logs.Info("Http服务已运行(%s)。", sillyGirl.GetString("port", "8080"))
go core.Server.Run("0.0.0.0:" + port)
logs.Info("关注频道 https://t.me/kczz2021 获取最新消息。")
reader := bufio.NewReader(os.Stdin)
d := false
for _, arg := range os.Args {
if arg == "-d" {
d = true
}
}
if !d {
for _, arg := range os.Args {
if arg == "-t" {
logs.Info("终端交互已启用。")
for {
data, _, _ := reader.ReadLine()
core.Senders <- &core.Faker{
Type: "terminal",
Message: string(data),
}
}
}
}
logs.Info("终端交互不可用,运行带-t参数即可启用。")
}
select {}
}
func monitorGoroutine() {
if runtime.GOOS == "windows" {
return
}
ticker := time.NewTicker(time.Millisecond * 100)
lastGNum := 0
for {
<-ticker.C
if newGNum := runtime.NumGoroutine(); lastGNum != newGNum {
lastGNum = newGNum
if newGNum > 800 {
utils.Daemon()
}
}
}
}