-
Notifications
You must be signed in to change notification settings - Fork 165
/
routers.go
55 lines (45 loc) · 1.26 KB
/
routers.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 routers
import (
"net/http"
"github.com/WeixinCloud/wxcloudrun-wxcomponent/api/admin"
"github.com/WeixinCloud/wxcloudrun-wxcomponent/api/authpage"
"github.com/WeixinCloud/wxcloudrun-wxcomponent/api/innerservice"
"github.com/WeixinCloud/wxcloudrun-wxcomponent/api/proxy"
"github.com/WeixinCloud/wxcloudrun-wxcomponent/api/wxcallback"
"github.com/WeixinCloud/wxcloudrun-wxcomponent/middleware"
"github.com/gin-gonic/gin"
)
type Option func(*gin.RouterGroup)
var options []Option
// Include 注册app的路由配置
func Include(opts ...Option) {
options = append(options, opts...)
}
// Init 初始化
func Init() *gin.Engine {
r := gin.Default()
r.Use(middleware.LogMiddleWare)
// 微信消息推送
wxcallback.Routers(r)
// 微管家
Include(admin.Routers, authpage.Routers)
g := r.Group("/wxcomponent")
for _, opt := range options {
opt(g)
}
// 静态文件
g.Static("/assets", "client/dist/wxcomponent/assets")
r.LoadHTMLGlob("client/dist/index.html")
r.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", nil)
})
r.NoRoute(proxy.ProxyHandler)
return r
}
// InnerServiceInit 内部服务初始化
func InnerServiceInit() *gin.Engine {
r := gin.Default()
r.Use(middleware.LogMiddleWare)
innerservice.Routers(r)
return r
}