-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Server structure & refactor api_{SVC}.go
- Loading branch information
1 parent
382ddee
commit 9867502
Showing
5 changed files
with
325 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,79 +7,45 @@ | |
* Generated by: OpenAPI Generator (https://openapi-generator.tech) | ||
*/ | ||
|
||
package AccessToken | ||
package sbi | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/free5gc/openapi-r17/models" | ||
Check failure on line 16 in internal/sbi/api_accesstoken.go GitHub Actions / build (1.18)
Check failure on line 16 in internal/sbi/api_accesstoken.go GitHub Actions / build (1.21)
|
||
"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("") | ||
|
||
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, | ||
}, | ||
|
||
{ | ||
Name: "AccessTokenRequest", | ||
Method: strings.ToUpper("Post"), | ||
Pattern: "/oauth2/token", | ||
HandlerFunc: HTTPAccessTokenRequest, | ||
}, | ||
func (s *Server) getAccessTokenEndpoints() []Endpoint { | ||
return []Endpoint{ | ||
{ | ||
Method: http.MethodPost, | ||
Pattern: "/oauth2/token", | ||
APIFunc: HTTPAccessTokenRequest, | ||
}, | ||
} | ||
} | ||
|
||
// AccessTokenRequest - Access Token Request | ||
func HTTPAccessTokenRequest(c *gin.Context) { | ||
c.JSON(http.StatusOK, gin.H{}) | ||
} | ||
|
||
func (s *Server) apiPostAccessToken(gc *gin.Context) { | ||
var atReq models.AccessTokenReq | ||
// the content type of AccessTokenReq shall be "application/x-www-urlencoded" | ||
if err := s.bindData(gc, &atReq); err != nil { | ||
return | ||
} | ||
|
||
hdlRsp := s.Processor().PostAccessToken(&atReq, context.Background()) | ||
|
||
// TODO: the content type of AccessTokenRsp shall be "application/x-www-urlencoded" | ||
s.buildAndSendHttpResponse(gc, hdlRsp, false) | ||
} |
Oops, something went wrong.