Merge remote-tracking branch 'origin/errcode' into errcode

# Conflicts:
#	cmd/api/main.go
#	internal/api/a2r/api2rpc.go
#	internal/apiresp/resp.go
#	internal/msgtransfer/online_history_msg_handler.go
#	internal/push/consumer_init.go
#	pkg/common/db/controller/conversation.go
#	pkg/common/mw/gin.go
#	pkg/statistics/statistics.go
This commit is contained in:
withchao
2023-03-16 10:51:00 +08:00
28 changed files with 306 additions and 151 deletions
+2
View File
@@ -15,11 +15,13 @@ func Call[A, B, C any](
) {
var req A
if err := c.BindJSON(&req); err != nil {
log.ZWarn(c, "gin bind json error", err, "req", req)
apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error())) // 参数错误
return
}
if check, ok := any(&req).(interface{ Check() error }); ok {
if err := check.Check(); err != nil {
log.ZWarn(c, "custom check error", err, "req", req)
apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error())) // 参数校验失败
return
}
+23 -21
View File
@@ -7,17 +7,17 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/gin-gonic/gin"
"github.com/go-redis/redis/v8"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"io"
"os"
)
func NewGinRouter(zk discoveryregistry.SvcDiscoveryRegistry) *gin.Engine {
func NewGinRouter(zk discoveryregistry.SvcDiscoveryRegistry, rdb redis.UniversalClient) *gin.Engine {
zk.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials())) // 默认RPC中间件
gin.SetMode(gin.ReleaseMode)
f, _ := os.Create("../logs/api.log")
gin.DefaultWriter = io.MultiWriter(f)
// gin.SetMode(gin.DebugMode)
//f, _ := os.Create("../logs/api.log")
//gin.DefaultWriter = io.MultiWriter(f)
//gin.SetMode(gin.DebugMode)
r := gin.New()
log.Info("load config: ", config.Config)
r.Use(gin.Recovery(), mw.CorsHandler(), mw.GinParseOperationID())
@@ -28,17 +28,18 @@ func NewGinRouter(zk discoveryregistry.SvcDiscoveryRegistry) *gin.Engine {
r.Use(prome.PrometheusMiddleware)
r.GET("/metrics", prome.PrometheusHandler())
}
zk.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials())) // 默认RPC中间件
userRouterGroup := r.Group("/user")
{
u := NewUser(zk)
userRouterGroup.POST("/user_register", u.UserRegister)
userRouterGroup.POST("/update_user_info", u.UpdateUserInfo) //1
userRouterGroup.POST("/set_global_msg_recv_opt", u.SetGlobalRecvMessageOpt)
userRouterGroup.POST("/get_users_info", u.GetUsersPublicInfo) //1
userRouterGroup.POST("/get_all_users_uid", u.GetAllUsersID) // todo
userRouterGroup.POST("/account_check", u.AccountCheck) // todo
userRouterGroup.POST("/get_users", u.GetUsers)
userRouterGroupChild1 := mw.NewRouterGroup(userRouterGroup, "",)
userRouterGroupChild2 := mw.NewRouterGroup(userRouterGroup, "", mw.WithGinParseToken(rdb))
userRouterGroupChild1.POST("/user_register", u.UserRegister)
userRouterGroupChild2.POST("/update_user_info", u.UpdateUserInfo) //1
userRouterGroupChild2.POST("/set_global_msg_recv_opt", u.SetGlobalRecvMessageOpt)
userRouterGroupChild2.POST("/get_users_info", u.GetUsersPublicInfo) //1
userRouterGroupChild2.POST("/get_all_users_uid", u.GetAllUsersID) // todo
userRouterGroupChild2.POST("/account_check", u.AccountCheck) // todo
userRouterGroupChild2.POST("/get_users", u.GetUsers)
}
////friend routing group
friendRouterGroup := r.Group("/friend")
@@ -56,7 +57,6 @@ func NewGinRouter(zk discoveryregistry.SvcDiscoveryRegistry) *gin.Engine {
friendRouterGroup.POST("/remove_black", f.RemoveBlack) //1
friendRouterGroup.POST("/import_friend", f.ImportFriends) //1
friendRouterGroup.POST("/is_friend", f.IsFriend) //1
}
groupRouterGroup := r.Group("/group")
g := NewGroup(zk)
@@ -94,10 +94,12 @@ func NewGinRouter(zk discoveryregistry.SvcDiscoveryRegistry) *gin.Engine {
{
a := NewAuth(zk)
u := NewUser(zk)
authRouterGroup.POST("/user_register", u.UserRegister) //1
authRouterGroup.POST("/user_token", a.UserToken) //1
authRouterGroup.POST("/parse_token", a.ParseToken) //1
authRouterGroup.POST("/force_logout", a.ForceLogout) //1
authRouterGroupChild1 := mw.NewRouterGroup(authRouterGroup, "",)
authRouterGroupChild2 := mw.NewRouterGroup(authRouterGroup, "", mw.WithGinParseToken(rdb))
authRouterGroupChild1.POST("/user_register", u.UserRegister) //1
authRouterGroupChild1.POST("/user_token", a.UserToken) //1
authRouterGroupChild2.POST("/parse_token", a.ParseToken) //1
authRouterGroupChild2.POST("/force_logout", a.ForceLogout) //1
}
////Third service
thirdGroup := r.Group("/third")
@@ -113,7 +115,6 @@ func NewGinRouter(zk discoveryregistry.SvcDiscoveryRegistry) *gin.Engine {
thirdGroup.POST("/confirm_put", t.ConfirmPut)
thirdGroup.GET("/get_url", t.GetURL)
thirdGroup.GET("/object", t.GetURL)
}
////Message
chatGroup := r.Group("/msg")
@@ -137,7 +138,7 @@ func NewGinRouter(zk discoveryregistry.SvcDiscoveryRegistry) *gin.Engine {
}
////Conversation
conversationGroup := r.Group("/conversation")
{ //1
{
c := NewConversation(zk)
conversationGroup.POST("/get_all_conversations", c.GetAllConversations)
conversationGroup.POST("/get_conversation", c.GetConversation)
@@ -149,3 +150,4 @@ func NewGinRouter(zk discoveryregistry.SvcDiscoveryRegistry) *gin.Engine {
}
return r
}