我正在嘗試從數據庫查詢中檢查結構是否為零,但它不起作用。 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)
}
- 1 回答
- 0 關注
- 116 瀏覽
添加回答
舉報
0/150
提交
取消