This repository has been archived by the owner on Apr 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
routers.go
100 lines (85 loc) · 1.8 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
/*
* Nsmf_EventExposure
*
* Session Management Event Exposure Service API
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package EventExposure
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("/nsmf_event-exposure/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)
}
}
return group
}
// Index is the index handler.
func Index(c *gin.Context) {
c.String(http.StatusOK, "Hello World!")
}
var routes = Routes{
{
"Index",
"GET",
"",
Index,
},
{
"SubscriptionsPost",
strings.ToUpper("Post"),
"subscriptions",
SubscriptionsPost,
},
{
"SubscriptionsSubIdDelete",
strings.ToUpper("Delete"),
"/subscriptions/:subId",
SubscriptionsSubIdDelete,
},
{
"SubscriptionsSubIdGet",
strings.ToUpper("Get"),
"/subscriptions/:subId",
SubscriptionsSubIdGet,
},
{
"SubscriptionsSubIdPut",
strings.ToUpper("Put"),
"/subscriptions/:subId",
SubscriptionsSubIdPut,
},
}