-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathrouter.go
76 lines (63 loc) · 1.8 KB
/
router.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
73
74
75
76
package main
import (
"net/http"
"data-view/config"
"data-view/handler"
"data-view/middleware"
"github.com/gin-gonic/gin"
"github.com/google/wire"
)
var RouterSet = wire.NewSet(wire.Struct(new(Router), "*"))
type Router struct {
DataSource *handler.DataSourceHandler
Image *handler.ImageHandler
DataView *handler.DataViewHandler
}
func (r *Router) NewRouter() (router *gin.Engine) {
gin.SetMode(gin.ReleaseMode)
router = gin.Default()
if config.Instance.App.AllowCrossDomain {
router.Use(middleware.Cors())
}
router.Use(middleware.ErrHandler())
router.StaticFS("/storage", http.Dir("storage"))
v1 := router.Group("/api/v1/")
{
// 状态
v1.GET("status", func(c *gin.Context) {
c.String(http.StatusOK, "start success")
})
// 数据源管理
dataSource := v1.Group("data-source/").Use(middleware.CheckUser())
{
dataSource.GET("/", r.DataSource.GetPage)
dataSource.GET("/list", r.DataSource.GetList)
}
// 图片管理
image := v1.Group("image/").Use(middleware.CheckUser())
{
image.GET("/", r.Image.GetPage)
image.GET("/list", r.Image.GetList)
image.GET("/upload.html", r.Image.UploadHtml)
image.POST("/", r.Image.Upload)
image.POST("/thumbnail", r.Image.UploadThumbnail)
}
// 数据可视化大屏管理
dataView := v1.Group("data-view/").Use(middleware.CheckUser())
{
dataView.GET("/", r.DataView.GetPage)
dataView.GET("/:id", r.DataView.Get)
dataView.POST("/", r.DataView.Create)
dataView.PUT("/", r.DataView.Update)
dataView.POST("/chart-data", r.DataView.GetChartData)
// 图表测试获取数据接口
dataView.GET("/test-chart-data", r.DataView.GetTestChartData)
}
// 数据报表管理
dataReport := v1.Group("data-report/").Use(middleware.CheckUser())
{
dataReport.GET("/", r.DataView.GetPage)
}
}
return
}