文書を挿入する際に問題が発生しました。Golangで配列文書を赤字に設定する方法は?
私は行くのデータの構造体を持っている:私はRedisのには、このようなデータを追加したい
type ArticleCovers struct {
ID int
Covers ArticleCovers
ArticleTypeID int
Address Address `gorm:"ForeignKey:AddressID"`
}
:
[ID:1 Cover:[http://chuabuuminh.vn/UserImages/2012/12/10/1/chinh_dien_jpg.jpg] ArticleTypeID:1 Address:map[Street: City:<nil> District:<nil> DistrictID:0 ID:0 Slug: Lat:0 Long:0 Ward:<nil> WardID:0 CityID:0]]
しかし、私はRedis.HMSet("test", structs.Map(ret))
を実行すると、エラーを返す:redis: can't marshal postgresql.ArticleCovers (consider implementing encoding.BinaryMarshaler)
を。
私の問題を解決するのに役立つ人は誰ですか?これが唯一のID
とArticleTypeID
フィールドを追加すること
type ArticleCovers struct {
ID int
Covers ArticleCovers
ArticleTypeID int
Address Address `gorm:"ForeignKey:AddressID"`
}
func (ac ArticleCovers) MarshalBinary() ([]byte, error) {
return []byte(fmt.Sprintf("%v-%v", ac.ID, ac.ArticleTypeID)), nil
}
注:エラーメッセージのよう