我是靠谱客的博主 风趣草丛,最近开发中收集的这篇文章主要介绍天秀--id被吞了?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

id被吞了?

func SetTaskReward(ctx context.Context, rewards models.Rewards) (interface{}, error) {
		for i, reward := range rewards.Rewards {
			
			id := utils.GetRewardID(i + 1)
			reward.Rewardid = id
			fmt.Println(reward)
		}
	
		fmt.Println(rewards)
		err := repo.SetTaskReward(rewards.Rewards)
		if err != nil {
			return nil, err
		}
		return rewards, nil
	}
1667321885u8dv6-1
{1667321885u8dv6-1 3419993186238465 veniam magna ootoken 999999 aoooooooooo minim 500 2014-03-13 21:36:53 token false}
{[{ 3419993186238465 veniam magna ootoken 999999 aoooooooooo minim 500 2014-03-13 21:36:53 token false}]}

type Reward struct {
	//gorm.Model
	Rewardid     string `json:"rewardid" gorm:"type:varchar(255)"`
	Missionid    int    `json:"missionid"`
	Blockchain   string `json:"blockchain" gorm:"type:varchar(255)"`
	Symbol       string `json:"symbol" gorm:"type:varchar(255)"`
	Rewardamount string `json:"rewardamount" gorm:"type:varchar(255)"`
	Contract     string `json:"contract" gorm:"type:varchar(255)"`
	Shares       int    `json:"shares"`
	Time         string `json:"time" gorm:"type:varchar(255)"`
	Type         string `json:"type" gorm:"type:varchar(255)"` //--eg: nft || token
	Onchain      bool   `json:"onchain"`
}

for i, reward := range rewards.Rewards {
		//if reward.Rewardid == "" {
		id := utils.GetRewardID(i + 1)
		reward.Rewardid = id
		//}
		rewardtest.Rewardid = reward.Rewardid
		rewardtest.Contract = reward.Contract
		fmt.Println(rewardtest)
		fmt.Println(reward)
	}
	fmt.Println(rewardtest)
	fmt.Println(rewards.Rewards)
	err := repo.SetTaskReward(rewards.Rewards)
1667322324Yikgj-1
{1667322324Yikgj-1 0    aoooooooooo minim 0   false}
{1667322324Yikgj-1 3419993186238465 veniam magna ootoken 999999 aoooooooooo minim 500 2014-03-13 21:36:53 token false}
{1667322324Yikgj-1 0    aoooooooooo minim 0   false}
[{ 3419993186238465 veniam magna ootoken 999999 aoooooooooo minim 500 2014-03-13 21:36:53 token false}]

for i, reward := range rewards {
		//reward.Rewardid = utils.GetRewardID(i + 1)
		fmt.Println(reward)
		rewards[i].Rewardid = utils.GetRewardID(i + 1)
		fmt.Println(reward)
	}
	fmt.Println(rewards)
{ 3419993186238465 veniam magna ootoken 999999 aoooooooooo minim 500 2014-03-13 21:36:53 token false}
1667322955nsw13-1
{ 3419993186238465 veniam magna ootoken 999999 aoooooooooo minim 500 2014-03-13 21:36:53 token false}
[{1667322955nsw13-1 3419993186238465 veniam magna ootoken 999999 aoooooooooo minim 500 2014-03-13 21:36:53 token false}]

用数组下标取,然后再赋值 竟然成功了


for i, reward := range rewards {
		//reward.Rewardid = utils.GetRewardID(i + 1)
		fmt.Println(reward)
		rewards[i].Rewardid = utils.GetRewardID(i + 1)
		reward.Rewardid = "11111"
		fmt.Println(reward)
		fmt.Println(rewards[i])
	}
	fmt.Println(rewards)
{ 3419993186238465 veniam magna ootoken 999999 aoooooooooo minim 500 2014-03-13 21:36:53 token false}
1667323186hvy0M-1
{11111 3419993186238465 veniam magna ootoken 999999 aoooooooooo minim 500 2014-03-13 21:36:53 token false}
{1667323186hvy0M-1 3419993186238465 veniam magna ootoken 999999 aoooooooooo minim 500 2014-03-13 21:36:53 token false}
[{1667323186hvy0M-1 3419993186238465 veniam magna ootoken 999999 aoooooooooo minim 500 2014-03-13 21:36:53 token false}]

测试了下竟然不是 同一个对象!!!得看看源码了

最后

以上就是风趣草丛为你收集整理的天秀--id被吞了?的全部内容,希望文章能够帮你解决天秀--id被吞了?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部