From 0fb9bc915789f9eb98dafdebb78ccf49ed0c93b1 Mon Sep 17 00:00:00 2001 From: smavros Date: Tue, 13 Aug 2019 11:15:36 +0200 Subject: [PATCH] Fix of User.ID serialization: As @skolen mentioned out, the `ID` field of the embedded struct `Model` in the model `User` must be serialized so it can be included in the responses. In the previous commit we completely ignored the field with the tag `json:"-"` so we can compare the serialized request (where ID was 0) with the response of the API. To limit the omission of the `User.ID` field only for the case that its value is 0 we modify the tag to `json:",omitempty"`. --- common/models.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/models.go b/common/models.go index 25fc7fe..298ac02 100644 --- a/common/models.go +++ b/common/models.go @@ -10,7 +10,7 @@ import ( // The type Model is exactly the same with gorm.Model (see jinzhu/gorm) // except the json tags that are needed for serializing the models type Model struct { - ID uint `json:"-" gorm:"unique;primary_key:true"` + ID uint `json:",omitempty" gorm:"unique;primary_key:true"` CreatedAt time.Time `json:"-"` UpdatedAt time.Time `json:"-"` DeletedAt *time.Time `json:"-" sql:"index"`