feat 包命名规范
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package http_gateway
|
||||
package httpgateway
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/http/http_resp"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/http/httpresp"
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"git.hlsq.asia/mmorpg/service-gateway/internal/global"
|
||||
"github.com/gin-contrib/cors"
|
||||
@@ -47,7 +47,7 @@ func authJwt() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
pList := strings.SplitN(c.Request.URL.Path, "/", 4)
|
||||
if len(pList) < 4 || pList[2] == "" {
|
||||
http_resp.JsonNotFound(c)
|
||||
httpresp.JsonNotFound(c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@@ -60,14 +60,14 @@ func authJwt() gin.HandlerFunc {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
http_resp.JsonUnauthorized(c)
|
||||
httpresp.JsonUnauthorized(c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
usn, _ := redis.GetClient().HGet(c, global.KeyGatewayAccessToken+token, (&utils.UserSession{}).GetUsnKey()).Int64()
|
||||
if usn == 0 {
|
||||
http_resp.JsonUnauthorized(c)
|
||||
httpresp.JsonUnauthorized(c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
package http_gateway
|
||||
package httpgateway
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.hlsq.asia/mmorpg/service-common/discover/common"
|
||||
"git.hlsq.asia/mmorpg/service-common/log"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/grpc/grpc_client"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/http/http_resp"
|
||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
||||
"git.hlsq.asia/mmorpg/service-gateway/internal/handler/http_handler"
|
||||
"git.hlsq.asia/mmorpg/service-gateway/internal/net/http_gateway/wrapper"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/grpc/grpcclient"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/http/httpresp"
|
||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/rspb"
|
||||
"git.hlsq.asia/mmorpg/service-gateway/internal/handler/httphandler"
|
||||
"git.hlsq.asia/mmorpg/service-gateway/internal/net/httpgateway/wrapper"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
@@ -61,11 +61,11 @@ func InitRouter() *gin.Engine {
|
||||
|
||||
r.HandleMethodNotAllowed = true
|
||||
r.NoMethod(func(c *gin.Context) {
|
||||
http_resp.JsonMethodNotAllowed(c)
|
||||
httpresp.JsonMethodNotAllowed(c)
|
||||
c.Abort()
|
||||
})
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
http_resp.JsonNotFound(c)
|
||||
httpresp.JsonNotFound(c)
|
||||
c.Abort()
|
||||
})
|
||||
|
||||
@@ -85,22 +85,22 @@ func InitRouter() *gin.Engine {
|
||||
func initGatewayPath(r *gin.RouterGroup) {
|
||||
g := r.Group("/" + common.KeyDiscoverServiceNameGateway)
|
||||
|
||||
g.POST("/open/login", http_handler.Login)
|
||||
g.POST("/open/refresh_token", http_handler.RefreshToken)
|
||||
g.POST("/open/logout", http_handler.Logout)
|
||||
g.POST("/open/login", httphandler.Login)
|
||||
g.POST("/open/refresh_token", httphandler.RefreshToken)
|
||||
g.POST("/open/logout", httphandler.Logout)
|
||||
}
|
||||
|
||||
func initUserPath(r *gin.RouterGroup) {
|
||||
g := r.Group("/" + common.KeyDiscoverServiceNameUser)
|
||||
|
||||
client, err := grpc_client.UserNewClientLB()
|
||||
client, err := grpcclient.UserNewClientLB()
|
||||
if err != nil {
|
||||
log.Errorf("get user conn failed: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
gwMux := InitServeMux()
|
||||
if err = grpc_pb.RegisterUserHandlerClient(context.Background(), gwMux, client); err != nil {
|
||||
if err = rspb.RegisterUserHandlerClient(context.Background(), gwMux, client); err != nil {
|
||||
log.Errorf("RegisterUserHandlerClient err: %v", err)
|
||||
return
|
||||
}
|
||||
@@ -111,14 +111,14 @@ func initUserPath(r *gin.RouterGroup) {
|
||||
func initQgdzsPath(r *gin.RouterGroup) {
|
||||
g := r.Group("/" + common.KeyDiscoverServiceNameQgdzs)
|
||||
|
||||
client, err := grpc_client.QgdzsNewClientLB()
|
||||
client, err := grpcclient.QgdzsNewClientLB()
|
||||
if err != nil {
|
||||
log.Errorf("get qgdzs conn failed: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
gwMux := InitServeMux()
|
||||
if err = grpc_pb.RegisterQgdzsHandlerClient(context.Background(), gwMux, client); err != nil {
|
||||
if err = rspb.RegisterQgdzsHandlerClient(context.Background(), gwMux, client); err != nil {
|
||||
log.Errorf("RegisterQgdzsHandlerClient err: %v", err)
|
||||
return
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package wrapper
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/http/http_resp"
|
||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/rs_common"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/http/httpresp"
|
||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/rscommon"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@@ -17,32 +17,32 @@ func ErrorHandler(_ context.Context, _ *runtime.ServeMux, _ runtime.Marshaler, w
|
||||
if !ok {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
_ = json.NewEncoder(w).Encode(http_resp.Error(http_resp.Failed))
|
||||
_ = json.NewEncoder(w).Encode(httpresp.Error(httpresp.Failed))
|
||||
return
|
||||
}
|
||||
|
||||
code, msg := 0, ""
|
||||
for _, detail := range st.Details() {
|
||||
if errorInfo, ok := detail.(*rs_common.ErrorInfo); ok {
|
||||
if errorInfo, ok := detail.(*rscommon.ErrorInfo); ok {
|
||||
code = int(errorInfo.Code)
|
||||
msg = errorInfo.Msg
|
||||
break
|
||||
}
|
||||
}
|
||||
if code == 0 {
|
||||
code = http_resp.Failed.Code()
|
||||
msg = http_resp.Failed.Error()
|
||||
code = httpresp.Failed.Code()
|
||||
msg = httpresp.Failed.Error()
|
||||
}
|
||||
if st.Code() == codes.Unknown || st.Code() == codes.Unimplemented || st.Code() == codes.NotFound {
|
||||
msg = st.Message()
|
||||
}
|
||||
if st.Code() == codes.NotFound {
|
||||
code = http_resp.NotFound.Code()
|
||||
code = httpresp.NotFound.Code()
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(grpcCodeToHTTPCode(st.Code()))
|
||||
_ = json.NewEncoder(w).Encode(http_resp.Error(http_resp.NewCode(code, msg)))
|
||||
_ = json.NewEncoder(w).Encode(httpresp.Error(httpresp.NewCode(code, msg)))
|
||||
}
|
||||
|
||||
// 这里定义 Internal 属于业务错误,其他的属于 500 报错
|
||||
@@ -2,7 +2,7 @@ package wrapper
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/http/http_resp"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/http/httpresp"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"io"
|
||||
)
|
||||
@@ -20,9 +20,9 @@ func NewWrappedMarshaler(inner runtime.Marshaler) *WrappedMarshaler {
|
||||
func (w *WrappedMarshaler) Marshal(v interface{}) ([]byte, error) {
|
||||
dataBytes, err := w.inner.Marshal(v)
|
||||
if err != nil {
|
||||
return json.Marshal(http_resp.Error(http_resp.Failed))
|
||||
return json.Marshal(httpresp.Error(httpresp.Failed))
|
||||
}
|
||||
return json.Marshal(http_resp.Success(json.RawMessage(dataBytes)))
|
||||
return json.Marshal(httpresp.Success(json.RawMessage(dataBytes)))
|
||||
}
|
||||
|
||||
func (w *WrappedMarshaler) Unmarshal(data []byte, v interface{}) error {
|
||||
@@ -1,11 +1,11 @@
|
||||
package ws_gateway
|
||||
package wsgateway
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.hlsq.asia/mmorpg/service-common/log"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/socket"
|
||||
"git.hlsq.asia/mmorpg/service-gateway/internal/handler/ws_handler/client"
|
||||
"git.hlsq.asia/mmorpg/service-gateway/internal/handler/ws_handler/login"
|
||||
"git.hlsq.asia/mmorpg/service-gateway/internal/handler/wshandler/client"
|
||||
"git.hlsq.asia/mmorpg/service-gateway/internal/handler/wshandler/login"
|
||||
"go.uber.org/zap"
|
||||
"time"
|
||||
)
|
||||
Reference in New Issue
Block a user