This repository has been archived by the owner on Apr 27, 2020. It is now read-only.
/
routers.go
130 lines (111 loc) · 2.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* NRF NFManagement Service
*
* NRF NFManagement Service
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package Management
import (
"net/http"
"strings"
"github.com/gin-gonic/gin"
)
// 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 := gin.Default()
AddService(router)
return router
}
func AddService(engine *gin.Engine) *gin.RouterGroup {
group := engine.Group("/nnrf-nfm/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,
},
{
"DeregisterNFInstance",
strings.ToUpper("Delete"),
"/nf-instances/:nfInstanceID",
DeregisterNFInstance,
},
{
"GetNFInstance",
strings.ToUpper("Get"),
"/nf-instances/:nfInstanceID",
GetNFInstance,
},
{
"RegisterNFInstance",
strings.ToUpper("Put"),
"/nf-instances/:nfInstanceID",
RegisterNFInstance,
},
{
"UpdateNFInstance",
strings.ToUpper("Patch"),
"/nf-instances/:nfInstanceID",
UpdateNFInstance,
},
{
"GetNFInstances",
strings.ToUpper("Get"),
"/nf-instances",
GetNFInstances,
},
{
"RemoveSubscription",
strings.ToUpper("Delete"),
"/subscriptions/:subscriptionID",
RemoveSubscription,
},
{
"UpdateSubscription",
strings.ToUpper("Patch"),
"/subscriptions/:subscriptionID",
UpdateSubscription,
},
{
"CreateSubscription",
strings.ToUpper("Post"),
"/subscriptions",
CreateSubscription,
},
}