-
Currently: type (
User struct {
UserId uint `gorm:"primaryKey;not null;autoIncrement:true" json:"userId"`
Username string `gorm:"not null" json:"username"`
Password string `gorm:"not null" json:"password"`
FirstName string `gorm:"not null" json:"firstName"`
LastName string `gorm:"not null" json:"lastName"`
UserRole string `gorm:"not null" json:"userRole"`
}
) When getting the table using map: var data map[string]interface{}
db.Model(&User{}).Find(&data)
//Return: map[first_name:V last_name:H password:12345 user_id:1 user_role:ADMIN username:vh] How do I get something like this instead?: //Return: map[firstName:V lastName:H password:12345 userId:1 userRole:ADMIN username:vh] (Noted all field names defined by JSON tag) I know I can use |
Beta Was this translation helpful? Give feedback.
Answered by
jinzhu
Sep 11, 2022
Replies: 1 comment
-
GORM don't support to use the json tag for the key, and I think it doesn't make much sense. For your question, maybe you can use db.Select("user_id as userId, last_name as lastName...").Model(&User{}).Find(&data) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
KiddoV
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GORM don't support to use the json tag for the key, and I think it doesn't make much sense.
For your question, maybe you can use