apitorpc group

test-errcode
withchao 2 years ago
parent 0411a5045b
commit 586a113994

@ -6,23 +6,44 @@ import (
"google.golang.org/grpc"
)
// Call TEST
func Call[A, B, C, D, E any](
apiReq *A,
apiResp *B,
rpc func(client E, ctx context.Context, req C, options ...grpc.CallOption) (D, error),
client func() (E, error),
c *gin.Context,
before func(apiReq *A, rpcReq *C, bind func() error) error,
after func(rpcResp *D, apiResp *B, bind func() error) error,
) {
//// Call TEST
//func Call2[A, B, C, D, E any](
// apiReq *A,
// apiResp *B,
// rpc func(client E, ctx context.Context, req C, options ...grpc.CallOption) (D, error),
// client func() (E, error),
// c *gin.Context,
// before func(apiReq *A, rpcReq *C, bind func() error) error,
// after func(rpcResp *D, apiResp *B, bind func() error) error,
//) {
//
//}
}
func Call1[C, D, E any](
rpc func(client E, ctx context.Context, req C, options ...grpc.CallOption) (D, error),
client func() (E, error),
func Call[A, B, C any](
rpc func(client C, ctx context.Context, req *A, options ...grpc.CallOption) (*B, error),
client func() (C, error),
c *gin.Context,
) {
var req A
if err := c.BindJSON(&req); err != nil {
// todo 参数错误
return
}
if check, ok := any(&req).(interface{ Check() error }); ok {
if err := check.Check(); err != nil {
// todo 参数校验失败
return
}
}
cli, err := client()
if err != nil {
// todo 获取rpc连接失败
return
}
resp, err := rpc(cli, c, &req)
if err != nil {
// todo rpc请求失败
return
}
_ = resp
}

@ -2,7 +2,6 @@ package group
import (
"OpenIM/internal/a2r"
"OpenIM/pkg/apistruct"
"OpenIM/pkg/common/config"
"OpenIM/pkg/proto/group"
"context"
@ -10,8 +9,10 @@ import (
"github.com/gin-gonic/gin"
)
func _() {
context.Background()
var _ context.Context = nil // 解决goland编辑器bug
func NewGroup(zk *openKeeper.ZkClient) *Group {
return &Group{zk: zk}
}
type Group struct {
@ -27,9 +28,9 @@ func (g *Group) getGroupClient() (group.GroupClient, error) {
}
func (g *Group) KickGroupMember(c *gin.Context) {
a2r.Call(&apistruct.KickGroupMemberReq{}, &apistruct.KickGroupMemberResp{}, group.GroupClient.KickGroupMember, g.getGroupClient, c, nil, nil)
a2r.Call(group.GroupClient.KickGroupMember, g.getGroupClient, c)
}
func (g *Group) GetGroupMembersInfo(c *gin.Context) {
a2r.Call1(group.GroupClient.GetGroupMembersInfo, g.getGroupClient, c)
a2r.Call(group.GroupClient.GetGroupMembersInfo, g.getGroupClient, c)
}

@ -82,31 +82,31 @@ func NewGinRouter() *gin.Engine {
c.Next()
})
{
groupRouterGroup.POST("/create_group", group.NewCreateGroup) //1
groupRouterGroup.POST("/set_group_info", group.NewSetGroupInfo) //1
groupRouterGroup.POST("/join_group", group.JoinGroup) //1
groupRouterGroup.POST("/quit_group", group.QuitGroup) //1
groupRouterGroup.POST("/group_application_response", group.ApplicationGroupResponse) //1
groupRouterGroup.POST("/transfer_group", group.TransferGroupOwner) //1
groupRouterGroup.POST("/get_recv_group_applicationList", group.GetRecvGroupApplicationList) //1
groupRouterGroup.POST("/get_user_req_group_applicationList", group.GetUserReqGroupApplicationList)
groupRouterGroup.POST("/get_groups_info", group.GetGroupsInfo) //1
groupRouterGroup.POST("/kick_group", group.KickGroupMember) //1
// groupRouterGroup.POST("/get_group_member_list", group.FindGroupMemberAll) //no use
groupRouterGroup.POST("/get_group_all_member_list", group.GetGroupAllMemberList) //1
groupRouterGroup.POST("/get_group_members_info", group.GetGroupMembersInfo) //1
groupRouterGroup.POST("/invite_user_to_group", group.InviteUserToGroup) //1
groupRouterGroup.POST("/get_joined_group_list", group.GetJoinedGroupList)
groupRouterGroup.POST("/dismiss_group", group.DismissGroup) //
groupRouterGroup.POST("/mute_group_member", group.MuteGroupMember)
groupRouterGroup.POST("/cancel_mute_group_member", group.CancelMuteGroupMember) //MuteGroup
groupRouterGroup.POST("/mute_group", group.MuteGroup)
groupRouterGroup.POST("/cancel_mute_group", group.CancelMuteGroup)
groupRouterGroup.POST("/set_group_member_nickname", group.SetGroupMemberNickname)
groupRouterGroup.POST("/set_group_member_info", group.SetGroupMemberInfo)
groupRouterGroup.POST("/get_group_abstract_info", group.GetGroupAbstractInfo)
//groupRouterGroup.POST("/get_group_all_member_list_by_split", group.GetGroupAllMemberListBySplit)
g := group.NewGroup(nil)
groupRouterGroup.POST("/create_group", g.NewCreateGroup) //1
groupRouterGroup.POST("/set_group_info", g.NewSetGroupInfo) //1
groupRouterGroup.POST("/join_group", g.JoinGroup) //1
groupRouterGroup.POST("/quit_group", g.QuitGroup) //1
groupRouterGroup.POST("/group_application_response", g.ApplicationGroupResponse) //1
groupRouterGroup.POST("/transfer_group", g.TransferGroupOwner) //1
groupRouterGroup.POST("/get_recv_group_applicationList", g.GetRecvGroupApplicationList) //1
groupRouterGroup.POST("/get_user_req_group_applicationList", g.GetUserReqGroupApplicationList)
groupRouterGroup.POST("/get_groups_info", g.GetGroupsInfo) //1
groupRouterGroup.POST("/kick_group", g.KickGroupMember) //1
// groupRouterGroup.POST("/get_group_member_list", g.FindGroupMemberAll) //no use
groupRouterGroup.POST("/get_group_all_member_list", g.GetGroupAllMemberList) //1
groupRouterGroup.POST("/get_group_members_info", g.GetGroupMembersInfo) //1
groupRouterGroup.POST("/invite_user_to_group", g.InviteUserToGroup) //1
groupRouterGroup.POST("/get_joined_group_list", g.GetJoinedGroupList)
groupRouterGroup.POST("/dismiss_group", g.DismissGroup) //
groupRouterGroup.POST("/mute_group_member", g.MuteGroupMember)
groupRouterGroup.POST("/cancel_mute_group_member", g.CancelMuteGroupMember) //MuteGroup
groupRouterGroup.POST("/mute_group", g.MuteGroup)
groupRouterGroup.POST("/cancel_mute_group", g.CancelMuteGroup)
groupRouterGroup.POST("/set_group_member_nickname", g.SetGroupMemberNickname)
groupRouterGroup.POST("/set_group_member_info", g.SetGroupMemberInfo)
groupRouterGroup.POST("/get_group_abstract_info", g.GetGroupAbstractInfo)
//groupRouterGroup.POST("/get_group_all_member_list_by_split", g.GetGroupAllMemberListBySplit)
}
superGroupRouterGroup := r.Group("/super_group")
{

Loading…
Cancel
Save