package rpc import ( "encoding/json" "git.hilo.cn/hilo-common/mylogrus" "git.hilo.cn/hilo-common/protocol/userProxy" "google.golang.org/protobuf/proto" ) func SendFruitMachine(date string, round uint32) error { msg := &userProxy.FruitMachine{ Date: date, Round: round, } if buffer, err := proto.Marshal(msg); err == nil { rspUids, err := broadcast(MsgFruitMachine, buffer) //记录socket,注意闭包问题 go func(userId uint64, msg *userProxy.FruitMachine, rspUids []uint64, err error) { buf, _ := json.Marshal(msg) AddRpcLog(MsgFruitMachine, userId, string(buf[:]), rspUids, err) }(0, msg, rspUids, err) if err != nil { mylogrus.MyLog.Errorf("grpc SendFruitMachine send fail") return err } else { mylogrus.MyLog.Info("grpc SendFruitMachine send success") } } else { return err } return nil } func SendGlobalRocketNotice(groupId string, period string, round uint32, stage uint32, fromUserId uint64, topUserIcon string, nick string, code string, avatar string) error { msg := &userProxy.GlobalRocketNotice{ GroupId: groupId, Period: period, Round: round, Stage: stage, TopUserIcon: topUserIcon, Nick: nick, Code: code, Avatar: avatar, } if buffer, err := proto.Marshal(msg); err == nil { rspUids, err := broadcast(MsgTypeGlobalRocketNotice, buffer) //记录socket,注意闭包问题 go func(userId uint64, msg *userProxy.GlobalRocketNotice, rspUids []uint64, err error) { buf, _ := json.Marshal(msg) AddRpcLog(MsgTypeGlobalRocketNotice, userId, string(buf[:]), rspUids, err) }(fromUserId, msg, rspUids, err) if err != nil { mylogrus.MyLog.Errorf("grpc GlobalRocketNotice send fail") return err } else { mylogrus.MyLog.Info("grpc GlobalRocketNotice send success") } } else { return err } return nil }