加入网络层
This commit is contained in:
44
Server/Gateway/net/http_gateway/router.go
Normal file
44
Server/Gateway/net/http_gateway/router.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package http_gateway
|
||||
|
||||
import (
|
||||
"gateway/config"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func InitRouter(cfg *config.Config) *gin.Engine {
|
||||
r := gin.Default()
|
||||
r.Use(gin.Recovery())
|
||||
r.Use(cors.New(getCorsConfig()))
|
||||
|
||||
r.MaxMultipartMemory = 8 << 20
|
||||
r.HandleMethodNotAllowed = true
|
||||
r.NoMethod(func(c *gin.Context) {
|
||||
c.JSON(http.StatusMethodNotAllowed, gin.H{
|
||||
"result": false,
|
||||
"error": "Method Not Allowed",
|
||||
})
|
||||
return
|
||||
})
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"result": false,
|
||||
"error": "Endpoint Not Found",
|
||||
})
|
||||
return
|
||||
})
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func getCorsConfig() cors.Config {
|
||||
return cors.Config{
|
||||
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"},
|
||||
AllowHeaders: []string{"Origin", "Content-Length", "Content-Type", "Authorization", "X-Forwarded-For", "User-Agent", "Referer", "X-Token", "token", "Token", "company-id", "lang", "source"},
|
||||
AllowCredentials: false,
|
||||
AllowAllOrigins: true,
|
||||
MaxAge: 12 * time.Hour,
|
||||
}
|
||||
}
|
||||
29
Server/Gateway/net/ws_gateway/server.go
Normal file
29
Server/Gateway/net/ws_gateway/server.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package ws_gateway
|
||||
|
||||
import (
|
||||
"common/net/socket"
|
||||
"time"
|
||||
)
|
||||
|
||||
type GatewayWsServer struct {
|
||||
}
|
||||
|
||||
func (g *GatewayWsServer) OnOpen(_ socket.ISocketConn) ([]byte, socket.Action) {
|
||||
return nil, socket.None
|
||||
}
|
||||
|
||||
func (g *GatewayWsServer) OnHandShake(conn socket.ISocketConn) {
|
||||
//query := conn.GetParam("query")
|
||||
}
|
||||
|
||||
func (g *GatewayWsServer) OnMessage(conn socket.ISocketConn, bytes []byte) socket.Action {
|
||||
return socket.None
|
||||
}
|
||||
|
||||
func (g *GatewayWsServer) OnClose(conn socket.ISocketConn, _ error) socket.Action {
|
||||
return socket.None
|
||||
}
|
||||
|
||||
func (g *GatewayWsServer) OnTick() (time.Duration, socket.Action) {
|
||||
return 5 * time.Second, socket.None
|
||||
}
|
||||
Reference in New Issue
Block a user