-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
berryhe
committed
Dec 13, 2021
1 parent
45ba668
commit 757ed18
Showing
15 changed files
with
317 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package agora | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func RegisterRoutes(agoraGroup *gin.RouterGroup) { | ||
|
||
agoraRoute := agoraGroup.Group("/agora") | ||
{ | ||
agoraRoute.POST("/token/generate/rtc", HandleGenRTCToken) | ||
agoraRoute.POST("/token/generate/rtm", HandleGenRTMToken) | ||
} | ||
} | ||
|
||
func HandleGenRTCToken(gCtx *gin.Context) { | ||
// TODO code | ||
} | ||
|
||
func HandleGenRTMToken(gCtx *gin.Context) { | ||
// TODO code | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cloudstorage | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func HandleAlibabaCloudRemove(gCtx *gin.Context) { | ||
// TODO code | ||
} | ||
func HandleAlibabaCloudRename(gCtx *gin.Context) { | ||
// TODO code | ||
} | ||
|
||
func HandleAlibabaCloudUploadStart(gCtx *gin.Context) { | ||
// TODO code | ||
} | ||
|
||
func HandleAlibabaCloudUploadFinish(gCtx *gin.Context) { | ||
// TODO code | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cloudstorage | ||
|
||
import "github.com/gin-gonic/gin" | ||
|
||
func RegisterRoutes(storageGroup *gin.RouterGroup) { | ||
|
||
storageRoute := storageGroup.Group("/cloud-storage") | ||
{ | ||
storageRoute.POST("/url-cloud/add", HandleUrlCloudAdd) | ||
storageRoute.POST("/url-cloud/remove", HandleUrlCloudRemove) | ||
storageRoute.POST("/url-cloud/rename", HandleUrlCloudRename) | ||
|
||
storageRoute.POST("/upload/cancel", HandleUploadCancel) | ||
storageRoute.POST("/list", HandleList) | ||
|
||
storageRoute.POST("/convert/start", handleConvertStart) | ||
storageRoute.POST("/convert/finish", handleConvertFinish) | ||
|
||
storageRoute.POST("/alibaba-cloud/upload/start", HandleAlibabaCloudUploadStart) | ||
storageRoute.POST("/alibaba-cloud/upload/finish", HandleAlibabaCloudUploadFinish) | ||
|
||
storageRoute.POST("/alibaba-cloud/remove", HandleAlibabaCloudRemove) | ||
storageRoute.POST("/alibaba-cloud/rename", HandleAlibabaCloudRename) | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cloudstorage | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func handleConvertStart(gCtx *gin.Context) { | ||
// TODO code | ||
} | ||
|
||
func handleConvertFinish(gCtx *gin.Context) { | ||
// TODO code | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package cloudstorage | ||
|
||
import "github.com/gin-gonic/gin" | ||
|
||
func HandleList(gCtx *gin.Context) { | ||
// TODO code | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package cloudstorage | ||
|
||
import "github.com/gin-gonic/gin" | ||
|
||
func HandleUploadCancel(gCtx *gin.Context) { | ||
// TODO code | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cloudstorage | ||
|
||
import "github.com/gin-gonic/gin" | ||
|
||
func HandleUrlCloudAdd(gCtx *gin.Context) { | ||
// TODO code | ||
} | ||
|
||
func HandleUrlCloudRemove(gCtx *gin.Context) { | ||
// TODO code | ||
} | ||
|
||
func HandleUrlCloudRename(gCtx *gin.Context) { | ||
// TODO code | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package login | ||
|
||
import "github.com/gin-gonic/gin" | ||
|
||
func HandleGithubCallback(gCtx *gin.Context) { | ||
// TODO code | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package login | ||
|
||
import "github.com/gin-gonic/gin" | ||
|
||
func RegisterRoutes(loginGroup *gin.RouterGroup) { | ||
loginRoutes := loginGroup.Group("/login") | ||
{ | ||
loginRoutes.GET("/github/callback", HandleGithubCallback) | ||
|
||
loginRoutes.GET("login/weChat/web/callback", HandleWechatWebCallback) | ||
loginRoutes.GET("login/weChat/mobile/callback", HandleWechatMobileCallback) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package login | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func HandleWechatMobileCallback(gCtx *gin.Context) { | ||
|
||
} | ||
|
||
func HandleWechatWebCallback(gCtx *gin.Context) { | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package room | ||
|
||
import "github.com/gin-gonic/gin" | ||
|
||
func RegisterRoutes(roomGroup *gin.RouterGroup) { | ||
// TODO register route. handle func | ||
roomRoute := roomGroup.Group("/room") | ||
{ | ||
roomRoute.POST("/cancel/history") | ||
roomRoute.POST("/cancel/ordinary") | ||
roomRoute.POST("/cancel/periodic") | ||
roomRoute.POST("/cancel/periodic-sub-room") | ||
|
||
roomRoute.POST("/create/ordinary") | ||
roomRoute.POST("/create/periodic") | ||
|
||
roomRoute.POST("/info/ordinary") | ||
roomRoute.POST("/info/periodic") | ||
roomRoute.POST("/info/periodic-sub-room") | ||
roomRoute.POST("/info/users") | ||
|
||
roomRoute.POST("/join") | ||
roomRoute.POST("/list/:type") | ||
|
||
roomRoute.POST("/record/info") | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package transport | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/netless-io/flat-server/api/middleware" | ||
"github.com/netless-io/flat-server/errors" | ||
"github.com/netless-io/flat-server/logger" | ||
) | ||
|
||
type Status int | ||
|
||
const ( | ||
NoLogin Status = -1 | ||
Success = iota - 1 | ||
Failed | ||
Process | ||
AuthFailed | ||
NotMethod | ||
NoRoute | ||
) | ||
|
||
type Response struct { | ||
gCtx *gin.Context | ||
traceLogger logger.Logger | ||
httpCode int | ||
userUUID string | ||
loginSource string | ||
|
||
Err error `json:"-"` | ||
Status int `json:"status"` | ||
Code int `json:"code,omitempty"` | ||
Data interface{} `json:"data,omitempty"` | ||
} | ||
|
||
func HandleNoMethod(gCtx *gin.Context) { | ||
resp := new(Response) | ||
resp.Status = NotMethod | ||
defer resp.JSONWithHTTPCode(http.StatusMethodNotAllowed) | ||
} | ||
|
||
func HandleNoRoute(gCtx *gin.Context) { | ||
resp := new(Response) | ||
resp.Status = NoRoute | ||
defer resp.JSONWithHTTPCode(http.StatusNotFound) | ||
} | ||
|
||
func NewResp(gCtx *gin.Context) *Response { | ||
traceLogger := getLogger(gCtx) | ||
userUUID, loginSource := getUserIDWithLoginSource(gCtx) | ||
|
||
return &Response{ | ||
gCtx: gCtx, | ||
userUUID: userUUID, | ||
loginSource: loginSource, | ||
traceLogger: traceLogger, | ||
httpCode: http.StatusOK, | ||
} | ||
} | ||
|
||
func getLogger(gCtx *gin.Context) logger.Logger { | ||
traceLog, exists := gCtx.Get("logger") | ||
if !exists { | ||
return middleware.NewTraceLog() | ||
} | ||
|
||
traceLogger, ok := traceLog.(*logger.TraceLog) | ||
if !ok { | ||
return middleware.NewTraceLog() | ||
} | ||
|
||
return traceLogger | ||
} | ||
|
||
func getUserIDWithLoginSource(gCtx *gin.Context) (string, string) { | ||
userAuth, exists := gCtx.Get("user_auth") | ||
if !exists { | ||
return "", "" | ||
} | ||
|
||
if userPayLoad, ok := userAuth.(middleware.UserPayLoad); ok { | ||
return userPayLoad.UserID, userPayLoad.LoginSource | ||
} | ||
|
||
return "", "" | ||
|
||
} | ||
|
||
func (resp *Response) JSONWithHTTPCode(httpCode int) { | ||
resp.httpCode = httpCode | ||
resp.JSON() | ||
} | ||
|
||
func (resp *Response) JSON() { | ||
defer resp.gCtx.JSON(resp.httpCode, resp) | ||
|
||
errCode, ok := resp.Err.(errors.Code) | ||
if !ok { | ||
resp.httpCode = http.StatusInternalServerError | ||
errCode = errors.ServerFail | ||
resp.Status = int(Failed) | ||
resp.Data = nil | ||
return | ||
} | ||
|
||
if resp.Code = errCode.Code(); resp.Code != 0 { | ||
resp.Data = nil | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package v1 | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/netless-io/flat-server/api/v1/agora" | ||
cloudstorage "github.com/netless-io/flat-server/api/v1/cloud_storage" | ||
"github.com/netless-io/flat-server/api/v1/login" | ||
"github.com/netless-io/flat-server/api/v1/room" | ||
transportV1 "github.com/netless-io/flat-server/api/v1/transport" | ||
) | ||
|
||
func RegisterAPIv1Routes(v1Group *gin.Engine) { | ||
v1Group.NoMethod(transportV1.HandleNoMethod) | ||
v1Group.NoRoute(transportV1.HandleNoRoute) | ||
|
||
apiV1 := v1Group.Group("/v1") | ||
{ | ||
agora.RegisterRoutes(apiV1) | ||
cloudstorage.RegisterRoutes(apiV1) | ||
room.RegisterRoutes(apiV1) | ||
login.RegisterRoutes(apiV1) | ||
} | ||
} |