-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.go
55 lines (49 loc) · 1.02 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
package main
import (
"chattyai-go/job"
"chattyai-go/models"
"chattyai-go/routers"
"chattyai-go/setting"
"fmt"
"github.com/urfave/cli/v2"
"log"
"net/http"
"os"
"strconv"
"time"
)
func main() {
app := &cli.App{
Name: "greet",
Usage: "fight the loneliness!",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Value: "conf/chattyai.ini",
Usage: "Load configuration from `FILE`",
},
},
Action: func(cCtx *cli.Context) error {
fmt.Println(cCtx.String("config"))
//
// 初始化数据库链接
setting.Setup(cCtx.String("config"))
models.Setup()
job.Init()
routerInit := routers.InitRouter()
s := &http.Server{
Addr: ":" + strconv.Itoa(setting.ServerSetting.HttpPort),
Handler: routerInit,
ReadTimeout: 60 * time.Second,
WriteTimeout: 60 * time.Second,
MaxHeaderBytes: 1 << 20,
}
err := s.ListenAndServe()
return err
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}