select json_agg(a.*) from users a where id = 1;
此时将json复制出来,需要是object形式的。
{"id":1090,"mobile_number":"10516","country_code":"86","status":9,"password":"","created_time":"2010-08-06T18:48:18.343005+08:00","updated_time":"2020-10-30T17:58:46.151487+08:00","wechat":null}
然后将json复制到goland中即可自动生成,生成后逐项检查下,因为有的null值会被转换为interface{}
type T2 struct {
Id int `json:"id"`
MobileNumber string `json:"mobile_number"`
CountryCode string `json:"country_code"`
Status int `json:"status"`
Password string `json:"password"`
CreatedTime time.Time `json:"created_time"`
UpdatedTime time.Time `json:"updated_time"`
Wechat interface{} `json:"wechat"`
}
最后改下名字即可