-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
91 lines (75 loc) · 1.82 KB
/
Copy pathmain.go
File metadata and controls
91 lines (75 loc) · 1.82 KB
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
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/colin-404/logx"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
"github.com/xid-protocol/attack-surface/aws"
"github.com/xid-protocol/xidp/biz"
)
var sig = make(chan os.Signal, 1)
func initConfig() string {
confPath := flag.String("c", "/opt/xidp/conf/config.yml", "config file path")
flag.Parse()
// confPath_str := common.NormalizePath(*confPath)
//如果配置文件不存在,则报错并关闭程序
if _, err := os.Stat(*confPath); os.IsNotExist(err) {
logx.Errorf("config file not found: %s", *confPath)
os.Exit(1)
}
//加载配置
return *confPath
}
func initLog() {
//初始化日志
logOpts := logx.Options{
LogFile: "/var/log/attack-surface/attack-surface.log",
MaxSize: 10,
MaxAge: 100,
MaxBackups: 100,
TimeFormat: logx.TimeFormats.RFC3339,
}
loger := logx.NewLoger(&logOpts)
logx.InitLogger(loger)
}
func init() {
//优雅关闭
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
//获取配置路径
confPath := initConfig()
//使用viper加载配置
viper.SetConfigFile(confPath)
viper.ReadInConfig()
initLog()
}
func main() {
awsCloud := aws.NewAWSCloud()
result := awsCloud.GetAllEC2Info()
logx.Infof("result: %d", len(result))
aws.GetPublicIP(result)
// go ServerStart()
//go sealsuite.SealsuiteAcountInit()
//go accounts.AccountMonitor()
<-sig
}
func ServerStart() {
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
biz.RegisterRouter(router)
//获取端口配置,如果获取不到,则退出
port := viper.GetInt("Server.port")
if port == 0 {
logx.Errorf("server.port is not set")
os.Exit(1)
}
logx.Infof("Listening and serving on %d", port)
err := router.Run(fmt.Sprintf(":%d", port))
if err != nil {
logx.Errorf("SRV_ERROR %s", err.Error())
}
<-sig
}