in game/go-server-game/pkg/provider.go [95:123]
func (p *BasketballService) Rank(ctx context.Context, uid string) (*pojo.Result, error) {
var (
rank = 1
info *pojo.Info
ok bool
)
// auto reply the same message
rsp, err := GateBasketball.Send(context.TODO(), uid, "")
if err != nil {
logger.Errorf("send fail: %#s", err.Error())
return &pojo.Result{Code: 1, Msg: err.Error()}, err
}
fmt.Println("receive data from gate:", rsp)
if info, ok = userMap[uid]; !ok {
logger.Error("no user found")
return &pojo.Result{Code: 1, Msg: "no user found", Data: map[string]interface{}{"to": uid, "rank": rank}}, nil
}
for _, v := range userMap {
if v.Score > info.Score {
rank++
}
}
return &pojo.Result{Code: 0, Msg: "success", Data: map[string]interface{}{"to": uid, "rank": rank}}, nil
}