-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmain.go
71 lines (62 loc) · 1.62 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
package main
import (
"fmt"
"github.com/go-ini/ini"
"github.com/robfig/cron"
log "github.com/sirupsen/logrus"
"myGoProjectNew/controllers"
"myGoProjectNew/myProjectUtils"
"myGoProjectNew/routers"
"os/exec"
"time"
)
func main() {
//now:=time.Now()
//fmt.Println(now.Format("2006-01-02 15:04:05") + "strart ......")
//flag.Parse()
cfg, err := ini.Load("conf/app.ini")
if err != nil {
fmt.Println(err)
}
myProjectUtils.Config = cfg
controllers.InitServer()
router := routers.InitRouter()
//定时器应用
cronInit()
port := cfg.Section("http").Key("port").String()
err1 := router.Run(port)
if err1 != nil {
fmt.Println(err)
log.Error(err)
}
urlLocal := "http://localhost" + port + "/myproject/"
fmt.Println("open", urlLocal)
cmd := exec.Command("explorer", urlLocal)
err2 := cmd.Start()
if err2 != nil {
fmt.Println(err2.Error())
}
}
//定时器
func cronInit() {
go func() {
crontab := cron.New()
crontab.AddFunc("*/5 * * * *", myfunc) //1 分钟
crontab.Start()
}()
}
// 加个定时器
func myfunc() {
fmt.Println(time.Now(), "10秒打印一次!!")
//fmt.Println("CPU Number:", runtime.NumCPU())
//fmt.Println("CPU Use:", utils.GetCpuPercent(), "%")
//fmt.Println("Disk Use:", utils.GetDiskPercent(), "%")
//fmt.Println("Memory user:", utils.GetMemPercent(), "%")
//
//info := models.PcResource{Id: primitive.NewObjectID(),
// DiskPercent: utils.GetDiskPercent(), CpuPercent: utils.GetCpuPercent(), CreateTime: time.Now().Unix()}
//result, err := db.InitMongoDB2().Collection(db.PcResource).InsertOne(context.Background(), info)
//if err == nil {
// fmt.Println(result.InsertedID)
//}
}