-
Notifications
You must be signed in to change notification settings - Fork 0
/
routers.go
114 lines (94 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
/*
* NudmUEAU
*
* UDM UE Authentication Service
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package ueauthentication
import (
"strings"
"github.com/nycu-ucr/gonet/http"
"github.com/nycu-ucr/gin"
"github.com/sirupsen/logrus"
"github.com/nycu-ucr/logger_util"
"github.com/nycu-ucr/udm/logger"
)
var HttpLog *logrus.Entry
func init() {
HttpLog = logger.HttpLog
}
// 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 genAuthDataHandlerFunc(c *gin.Context) {
c.Params = append(c.Params, gin.Param{Key: "supiOrSuci", Value: c.Param("supi")})
if strings.ToUpper("Post") == c.Request.Method {
HttpGenerateAuthData(c)
return
}
c.String(http.StatusNotFound, "404 page not found")
}
func AddService(engine *gin.Engine) *gin.RouterGroup {
group := engine.Group("/nudm-ueau/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)
}
}
genAuthDataPath := "/:supi/security-information/generate-auth-data"
group.Any(genAuthDataPath, genAuthDataHandlerFunc)
return group
}
// Index is the index handler.
func Index(c *gin.Context) {
c.String(http.StatusOK, "Hello World!")
}
var routes = Routes{
{
"Index",
"GET",
"/",
Index,
},
{
"ConfirmAuth",
strings.ToUpper("Post"),
"/:supi/auth-events",
HTTPConfirmAuth,
},
}
var specialRoutes = Routes{
{
"GenerateAuthData",
strings.ToUpper("Post"),
"/:supiOrSuci/security-information/generate-auth-data",
HttpGenerateAuthData,
},
}