mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-12 04:55:59 +08:00
1
This commit is contained in:
+676
-676
File diff suppressed because it is too large
Load Diff
@@ -5,27 +5,53 @@ import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/common/config"
|
||||
rpc "Open_IM/pkg/proto/friend"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 不一致
|
||||
func AddBlacklist(c *gin.Context) {
|
||||
common.ApiToRpc(c, &api.AddBlacklistReq{}, &api.AddBlacklistResp{},
|
||||
config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, utils.GetSelfFuncName())
|
||||
func AddBlack(c *gin.Context) {
|
||||
common.ApiToRpc(c, &api.AddBlacklistReq{}, &api.AddBlacklistResp{}, config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, "")
|
||||
}
|
||||
|
||||
func ImportFriend1(c *gin.Context) {
|
||||
common.ApiToRpc(c, &api.ImportFriendReq{}, &api.ImportFriendResp{},
|
||||
config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, utils.GetSelfFuncName())
|
||||
func ImportFriend(c *gin.Context) {
|
||||
common.ApiToRpc(c, &api.ImportFriendReq{}, &api.ImportFriendResp{}, config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, "")
|
||||
}
|
||||
|
||||
func AddFriend1(c *gin.Context) {
|
||||
common.ApiToRpc(c, &api.AddFriendReq{}, &api.AddFriendResp{},
|
||||
config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, utils.GetSelfFuncName())
|
||||
func AddFriend(c *gin.Context) {
|
||||
common.ApiToRpc(c, &api.AddFriendReq{}, &api.AddFriendResp{}, config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, "")
|
||||
}
|
||||
|
||||
func AddFriendResponse1(c *gin.Context) {
|
||||
common.ApiToRpc(c, &api.AddFriendResponseReq{}, &api.AddFriendResponseResp{},
|
||||
config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, utils.GetSelfFuncName())
|
||||
func AddFriendResponse(c *gin.Context) {
|
||||
common.ApiToRpc(c, &api.AddFriendResponseReq{}, &api.AddFriendResponseResp{}, config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, "")
|
||||
}
|
||||
|
||||
func DeleteFriend(c *gin.Context) {
|
||||
common.ApiToRpc(c, &api.DeleteFriendReq{}, &api.DeleteFriendResp{}, config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, "")
|
||||
}
|
||||
|
||||
func GetBlacklist(c *gin.Context) {
|
||||
common.ApiToRpc(c, &api.GetBlackListReq{}, &api.GetBlackListResp{}, config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, "")
|
||||
}
|
||||
|
||||
func SetFriendRemark(c *gin.Context) {
|
||||
common.ApiToRpc(c, &api.SetFriendRemarkReq{}, &api.SetFriendRemarkResp{}, config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, "")
|
||||
}
|
||||
|
||||
func RemoveBlacklist(c *gin.Context) {
|
||||
common.ApiToRpc(c, &api.RemoveBlacklistReq{}, &api.RemoveBlacklistResp{}, config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, "")
|
||||
}
|
||||
|
||||
func IsFriend(c *gin.Context) {
|
||||
common.ApiToRpc(c, &api.IsFriendReq{}, &api.IsFriendResp{}, config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, "")
|
||||
}
|
||||
|
||||
func GetFriendList(c *gin.Context) {
|
||||
common.ApiToRpc(c, &api.GetFriendListReq{}, &api.GetFriendListResp{}, config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, "")
|
||||
}
|
||||
|
||||
func GetFriendApplyList(c *gin.Context) {
|
||||
common.ApiToRpc(c, &api.GetFriendApplyListReq{}, &api.GetFriendApplyListResp{}, config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, "")
|
||||
}
|
||||
|
||||
func GetSelfApplyList(c *gin.Context) {
|
||||
common.ApiToRpc(c, &api.GetSelfApplyListReq{}, &api.GetSelfApplyListResp{}, config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, "")
|
||||
}
|
||||
|
||||
@@ -11,11 +11,10 @@ import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
//func a(c *gin.Context) {
|
||||
// ApiToRpc(c, &api.AddBlacklistReq{}, &api.AddBlacklistResp{}, config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, utils.GetSelfFuncName())
|
||||
//}
|
||||
|
||||
func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, rpcClientFunc interface{}, rpcFuncName string) {
|
||||
if rpcName == "" {
|
||||
rpcName = utils2.GetFuncName(1)
|
||||
}
|
||||
logFuncName := fmt.Sprintf("[ApiToRpc: %s]%s", utils2.GetFuncName(1), rpcFuncName)
|
||||
ctx := trace_log.NewCtx1(c, rpcFuncName)
|
||||
defer log.ShowLog(ctx)
|
||||
@@ -58,77 +57,3 @@ func rpcString(v interface{}) string {
|
||||
}
|
||||
return fmt.Sprintf("%+v", v)
|
||||
}
|
||||
|
||||
//func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, fn interface{}, rpcFuncName string, tokenFunc func(token string, operationID string) (string, error)) {
|
||||
// nCtx := trace_log.NewCtx(c, rpcFuncName)
|
||||
// defer trace_log.ShowLog(nCtx)
|
||||
// if err := c.BindJSON(apiReq); err != nil {
|
||||
// trace_log.WriteErrorResponse(nCtx, "BindJSON", err)
|
||||
// return
|
||||
// }
|
||||
// reqValue := reflect.ValueOf(apiReq).Elem()
|
||||
// operationID := reqValue.FieldByName("OperationID").String()
|
||||
// trace_log.SetOperationID(nCtx, operationID)
|
||||
// trace_log.SetCtxInfo(nCtx, "BindJSON", nil, "params", apiReq)
|
||||
// etcdConn, err := utils2.GetConn(c, rpcName)
|
||||
// if err != nil {
|
||||
// trace_log.WriteErrorResponse(nCtx, "GetDefaultConn", err)
|
||||
// return
|
||||
// }
|
||||
// rpc := reflect.ValueOf(fn).Call([]reflect.Value{
|
||||
// reflect.ValueOf(etcdConn),
|
||||
// })[0].MethodByName(rpcFuncName) // rpc func
|
||||
// rpcReqPtr := reflect.New(rpc.Type().In(1).Elem()) // *req参数
|
||||
// var opUserID string
|
||||
// if tokenFunc != nil {
|
||||
// var err error
|
||||
// opUserID, err = tokenFunc(c.GetHeader("token"), operationID)
|
||||
// if err != nil {
|
||||
// trace_log.WriteErrorResponse(nCtx, "TokenFunc", err)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
// if opID := rpcReqPtr.Elem().FieldByName("OperationID"); opID.IsValid() {
|
||||
// opID.SetString(operationID)
|
||||
// if opU := rpcReqPtr.Elem().FieldByName("OpUserID"); opU.IsValid() {
|
||||
// opU.SetString(opUserID)
|
||||
// }
|
||||
// } else {
|
||||
// op := rpcReqPtr.Elem().FieldByName("Operation").Elem()
|
||||
// op.FieldByName("OperationID").SetString(operationID)
|
||||
// op.FieldByName("OpUserID").SetString(opUserID)
|
||||
// }
|
||||
// if err := utils.CopyStructFields(rpcReqPtr.Interface(), apiReq); err != nil {
|
||||
// trace_log.WriteErrorResponse(nCtx, "CopyStructFields_RpcReq", err)
|
||||
// return
|
||||
// }
|
||||
// respArr := rpc.Call([]reflect.Value{
|
||||
// reflect.ValueOf(context.Context(c)), // context.Context
|
||||
// rpcReqPtr, // rpc apiReq
|
||||
// }) // respArr => (apiResp, error)
|
||||
// if !respArr[1].IsNil() { // rpc err != nil
|
||||
// err := respArr[1].Interface().(error)
|
||||
// trace_log.WriteErrorResponse(nCtx, rpcFuncName, err, "rpc req", rpcReqPtr.Interface())
|
||||
// return
|
||||
// }
|
||||
// rpcResp := respArr[0].Elem()
|
||||
// trace_log.SetCtxInfo(nCtx, rpcFuncName, nil, "rpc req", rpcReqPtr.Interface(), "resp", rpcResp.Interface())
|
||||
// commonResp := rpcResp.FieldByName("CommonResp").Elem()
|
||||
// errCodeVal := commonResp.FieldByName("ErrCode")
|
||||
// errMsgVal := commonResp.FieldByName("ErrMsg").Interface().(string)
|
||||
// errCode := errCodeVal.Interface().(int32)
|
||||
// if errCode != 0 {
|
||||
// trace_log.WriteErrorResponse(nCtx, "RpcErrCode", &constant.ErrInfo{
|
||||
// ErrCode: errCode,
|
||||
// ErrMsg: errMsgVal,
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// if apiResp != nil {
|
||||
// if err := utils.CopyStructFields(apiResp, rpcResp.Interface()); err != nil {
|
||||
// trace_log.WriteErrorResponse(nCtx, "CopyStructFields_RpcResp", err)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
// trace_log.SetSuccess(nCtx, rpcFuncName, apiResp)
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user