-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.go
77 lines (49 loc) · 1.56 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
77
package main
import (
"gopkg.in/gin-gonic/gin.v1"
. "taskweb/apis"
)
func initRouter() *gin.Engine {
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
//cors
router.Use(MiddleWare())
router.GET("/", IndexApi)
router.POST("/category", AddTbCategoryApi)
router.POST("/delcategory", DelCategoryApi)
router.GET("/categorys", GetTbCategorysApi)
router.POST("/login", LoginApi)
router.OPTIONS("/categorys", GetTbCategorysApi)
router.OPTIONS("/login", LoginApi)
router.OPTIONS("/jobs", GetJobsApi)
router.GET("/jobs", GetJobsApi)
router.POST("/job", AddJobApi)
router.PUT("/job", PutJobApi)
router.OPTIONS("/job", PutJobApi)
router.POST("/node", AddTbNodeApi)
router.POST("/delnode", DelNodeApi)
router.GET("/nodes", GetTbNodesApi)
router.OPTIONS("/nodes", GetTbNodesApi)
router.POST("/command", AddTbCommandApi)
router.GET("/commands", GetTbCommandsApi)
router.OPTIONS("/commands", GetTbCommandsApi)
router.OPTIONS("/logs", GetTbErrorsApi)
router.GET("/logs", GetTbErrorsApi)
router.OPTIONS("/performances", GetTbPerformancesApi)
router.GET("/performances", GetTbPerformancesApi)
//
//router.PUT("/person/:id", ModPersonApi)
//
return router
}
//cors
func MiddleWare() gin.HandlerFunc {
return func(c *gin.Context) {
//c.Request.SetBasicAuth("x","x")
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")//允许访问所有域
c.Writer.Header().Add("Access-Control-Allow-Headers","Content-Type")//header的类型
//c.Writer.Header().Set("content-type","application/json") //返回数据格式是json
c.Next()
//}
}
}