-
Notifications
You must be signed in to change notification settings - Fork 0
/
routers.go
105 lines (89 loc) · 2.02 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* Npcf_AMPolicyControl
*
* Access and Mobility Policy Control Service API
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package ampolicy
import (
"strings"
"github.com/nycu-ucr/gonet/http"
"github.com/nycu-ucr/gin"
"github.com/nycu-ucr/logger_util"
"github.com/nycu-ucr/pcf/logger"
)
// Route is the information for every URI.
type Route struct {
// Name is the name of this Route.
Name string
// Method is the string for the HTTP method. ex) GET, POST etc..
Method string
// Pattern is the pattern of the URI.
Pattern string
// HandlerFunc is the handler function of this route.
HandlerFunc gin.HandlerFunc
}
// Routes is the list of the generated Route.
type Routes []Route
// NewRouter returns a new router.
func NewRouter() *gin.Engine {
router := logger_util.NewGinWithLogrus(logger.GinLog)
AddService(router)
return router
}
func AddService(engine *gin.Engine) *gin.RouterGroup {
group := engine.Group("/npcf-am-policy-control/v1")
for _, route := range routes {
switch route.Method {
case "GET":
group.GET(route.Pattern, route.HandlerFunc)
case "POST":
group.POST(route.Pattern, route.HandlerFunc)
case "PUT":
group.PUT(route.Pattern, route.HandlerFunc)
case "DELETE":
group.DELETE(route.Pattern, route.HandlerFunc)
case "PATCH":
group.PATCH(route.Pattern, route.HandlerFunc)
}
}
return group
}
// Index is the index handler.
func Index(c *gin.Context) {
c.String(http.StatusOK, "Hello World!")
}
var routes = Routes{
{
"Index",
"GET",
"/",
Index,
},
{
"HTTPPoliciesPolAssoIdDelete",
strings.ToUpper("Delete"),
"/policies/:polAssoId",
HTTPPoliciesPolAssoIdDelete,
},
{
"HTTPPoliciesPolAssoIdGet",
strings.ToUpper("Get"),
"/policies/:polAssoId",
HTTPPoliciesPolAssoIdGet,
},
{
"HTTPPoliciesPolAssoIdUpdatePost",
strings.ToUpper("Post"),
"/policies/:polAssoId/update",
HTTPPoliciesPolAssoIdUpdatePost,
},
{
"HTTPPoliciesPost",
strings.ToUpper("Post"),
"/policies",
HTTPPoliciesPost,
},
}