-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
72 lines (63 loc) · 1.88 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
72
package main
import (
"github.com/reallovelei/ggg/app/command"
"github.com/reallovelei/ggg/app/web"
"github.com/reallovelei/ggg/framework"
"github.com/reallovelei/ggg/framework/provider/app"
"github.com/reallovelei/ggg/framework/provider/config"
distributed "github.com/reallovelei/ggg/framework/provider/distribute"
"github.com/reallovelei/ggg/framework/provider/env"
"github.com/reallovelei/ggg/framework/provider/kernel"
"github.com/reallovelei/ggg/framework/provider/log"
"github.com/reallovelei/ggg/framework/provider/orm"
)
func main() {
// 初始化服务容器
container := framework.NewContainer()
// 绑定服务提供者
container.Bind(&app.GGGAppProvider{})
container.Bind(&env.GGGEnvProvider{})
container.Bind(&distributed.LocalDistributedProvider{})
container.Bind(&config.GGGConfigProvider{})
container.Bind(&log.GGGLogServiceProvider{})
container.Bind(&orm.GormProvider{})
if engine, err := web.NewHttpEngine(); err == nil {
container.Bind(&kernel.GGGKernelProvider{HttpEngine: engine})
}
command.RunCommand(container)
// 创建 engine 结构
//core := gin.New()
//
//
//// bind service
//core.Bind(&app.GGGAppProvider{BasePath:"/tmp"})
//
//core.Use(gin.Recovery())
//
//core.Use(middleware.Cost())
//RegisterRouter(core)
//
//server := &web.Server {
// Handler:core,
// Addr:":8888",
//}
//
//// 使用一个协程来 监听服务
//go func() {
// server.ListenAndServe()
//}()
//
//quit := make(chan os.Signal)
//// 监控信号:SIGINT, SIGTERM, SIGQUIT
//signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
//// 这里会阻塞当前goroutine等待信号
//<-quit
//
//// 调用Server.Shutdown graceful结束
//timeoutCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
//defer cancel()
//
//if err := server.Shutdown(timeoutCtx); err != nil {
// log.Fatal("Server Shutdown:", err)
//}
}