-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
58 lines (44 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
56
57
58
package main
import (
"net/http"
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
"github.com/usoftglobal/seckill/controllers"
"github.com/usoftglobal/seckill/models"
"github.com/usoftglobal/seckill/services"
)
// 应用入口
func main() {
app()
}
// 秒杀应用
func app() {
// 订单处理队列
go (&services.SeckillService{}).OrderHandel()
// GIN Framework
ginFramework()
}
func ginFramework() {
gin.SetMode(gin.ReleaseMode)
ginEngine := gin.New()
pprof.Register(ginEngine, "dd/pprof")
ginEngine = setupRouter(ginEngine)
ginEngine.Run(":3000")
defer models.DB.Close()
}
func setupRouter(r *gin.Engine) *gin.Engine {
goods := new(controllers.GoodsController)
seckill := new(controllers.SeckillController)
r.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "Hello Golang!")
})
// 清空
r.GET("/clear", goods.Clear)
// 商品
r.GET("/goods", goods.All)
r.GET("/goods/:id", goods.Detail)
r.GET("/goodsCreate", goods.Create)
// 秒杀
r.GET("/seckill/buy", seckill.Buy)
return r
}