forked from Huochengyan/myGoProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·48 lines (41 loc) · 823 Bytes
/
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
package main
import (
"fmt"
"github.com/robfig/cron"
"myProject/routers"
"os/exec"
"runtime"
)
func main() {
router := routers.InitRouter()
cronInit()
err := router.Run(":8888") // listen and serve on 0.0.0.0:8080
if err != nil {
panic(err)
}
fmt.Println("strart ......")
//调用浏览器打开页面
//OpenUrl("https://www.baidu.com")
//browser.OpenURL("http://www.baidu.com")
}
var commands = map[string]string{
"windows": "cmd /c start",
"darwin": "open",
"linux": "xdg-open",
}
func OpenUrl(uri string) {
run, _ := commands[runtime.GOOS]
exec.Command(run, uri).Start()
}
//定时器
func cronInit() {
go func() {
crontab := cron.New()
crontab.AddFunc("*/5 * * * *", myfunc) //5S
crontab.Start()
}()
}
// 加个定时器
func myfunc() {
//fmt.Println("5秒打印一次!!")
}