-
Notifications
You must be signed in to change notification settings - Fork 307
/
main.go
94 lines (81 loc) · 1.91 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
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 (
"fmt"
"github.com/fvbock/endless"
"linglong/global"
"linglong/models"
"linglong/pkg/jobs"
"linglong/pkg/setting"
"linglong/routers"
v1 "linglong/routers/api/v1"
"log"
"strings"
"syscall"
"time"
)
func init() {
err := setupSetting()
if err != nil {
log.Fatalf("init.setupSetting err: %v", err)
}
jobs.InitJobs()
}
func main() {
endless.DefaultReadTimeOut = global.ServerSetting.ReadTimeout
endless.DefaultWriteTimeOut = global.ServerSetting.WriteTimeout
endless.DefaultMaxHeaderBytes = 1 << 20
endPoint := fmt.Sprintf(":%d", global.ServerSetting.HttpPort)
server := endless.NewServer(endPoint, routers.InitRouter())
server.BeforeBegin = func(add string) {
log.Printf("Actual pid is %d", syscall.Getpid())
}
//启动一个无限循环扫描的masscan+nmap端口识别
go func() {
defer func() {
if err := recover(); err != nil {
fmt.Println("masscan 运行错误:", err)
}
}()
i := 1
for {
start := time.Now()
v1.InitMasscan()
end := time.Now()
log.Printf("masscan完成第 %d 轮扫描 耗时: %s\n", i, end.Sub(start))
i++
time.Sleep(10 * time.Second)
}
}()
err := server.ListenAndServe()
if err != nil {
log.Printf("Server err: %v", err)
}
}
func setupSetting() error {
s, err := setting.NewSetting(strings.Split("configs/", ",")...)
if err != nil {
return err
}
err = s.ReadSection("Server", &global.ServerSetting)
if err != nil {
return err
}
err = s.ReadSection("App", &global.AppSetting)
if err != nil {
return err
}
err = s.ReadSection("Database", &global.DatabaseSetting)
if err != nil {
return err
}
err = s.ReadSection("Masscan", &global.MasscanSetting)
if err != nil {
return err
}
global.AppSetting.DefaultContextTimeout *= time.Second
//global.JWTSetting.Expire *= time.Second
global.ServerSetting.ReadTimeout *= time.Second
global.ServerSetting.WriteTimeout *= time.Second
models.Setup()
return nil
}