亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 golang 中檢查 &{<nil> }

如何在 golang 中檢查 &{<nil> }

Go
鳳凰求蠱 2022-10-24 16:01:11
我正在嘗試從數據庫查詢中檢查結構是否為零,但它不起作用。 fmt.Println(loginResponse) // &{<nil>   }if !reflect.ValueOf(loginResponse).IsNil() { // Its not working        response := models.Response{            Message: "Login Success",            Success: true,            Output:  token,        }        return c.JSON(response)    } if !reflect.ValueOf(loginResponse).IsZero() { // its also not working        response := models.Response{            Message: "Login Success",            Success: true,            Output:  token,        }        return c.JSON(response)    } 這兩個條件都不起作用。請幫忙登錄響應type LoginResponse struct {    Id          interface{} `json:"_id,omitempty" bson:"_id,omitempty"`    Email       string      `json:"email"`    Gender      string      `json:"gender"`    PhoneNumber string      `json:"phonenumber"`}
查看完整描述

1 回答

?
手掌心

TA貢獻1942條經驗 獲得超3個贊

嘗試這樣做,希望它有效


if (LoginResponse{}) != *loginResponse { // as your getting address so derferencing the pointer to struct


        response := models.Response{

            Message: "Login Success",

            Success: true,

            Output:  token,

        }

        return c.JSON(response)


    }


查看完整回答
反對 回復 2022-10-24
  • 1 回答
  • 0 關注
  • 116 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號