You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/api/group/quit_group.go

47 lines
1.6 KiB

3 years ago
package group
import (
pb "Open_IM/pkg/proto/group"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
3 years ago
"context"
"github.com/gin-gonic/gin"
"net/http"
"strings"
)
type paramsQuitGroup struct {
GroupID string `json:"groupID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
func QuitGroup(c *gin.Context) {
log.Info("", "", "api quit group init ....")
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
client := pb.NewGroupClient(etcdConn)
//defer etcdConn.Close()
3 years ago
params := paramsQuitGroup{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &pb.QuitGroupReq{
GroupID: params.GroupID,
OperationID: params.OperationID,
Token: c.Request.Header.Get("token"),
}
log.Info(req.Token, req.OperationID, "api quit group is server,params=%s", req.String())
RpcResp, err := client.QuitGroup(context.Background(), req)
if err != nil {
log.Error(req.Token, req.OperationID, "call quit group rpc server failed,err=%s", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
return
}
log.InfoByArgs("call quit group rpc server success,args=%s", RpcResp.String())
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
log.InfoByArgs("api quit group success return,get args=%s,return args=%s", req.String(), RpcResp.String())
}