-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
47 lines (37 loc) · 839 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
package main
import (
"context"
"github.com/lexkong/log"
"github.com/locxiang/waiwai-spider/config"
"github.com/locxiang/waiwai-spider/model"
"github.com/locxiang/waiwai-spider/waiwai"
"github.com/spf13/pflag"
"runtime"
)
var (
cfg = pflag.StringP("config", "c", "", "config file path.")
)
func main() {
//使用全部cpu
runtime.GOMAXPROCS(runtime.NumCPU())
pflag.Parse()
// 初始化配置文件
if err := config.Init(*cfg); err != nil {
panic(err)
}
mysqlCfg := config.Values.Mysql
cfg := model.Config{
UserName: mysqlCfg.User,
Password: mysqlCfg.Pass,
Addr: mysqlCfg.Addr,
DbName: mysqlCfg.DB,
}
if err := model.ConnDB(cfg); err != nil {
panic(err)
}
ctx, cancel := context.WithCancel(context.Background())
waiwai.New(ctx, cancel)
waiwai.RunEntry()
<-ctx.Done()
log.Info("完成")
}