Skip to content

slice implement encoding.BinaryMarshaler #1554

@ghost

Description

type Article struct {
	Id          int64         `json:"id"`
	Title       string        `json:"title"`
}
func (m *Article) UnmarshalBinary(data []byte) error {
	return json.Unmarshal(data, m)
}

func (m *Article) MarshalBinary() (data []byte, err error) {
	return json.Marshal(m)
}
var context.Background()
var value = []&Article{
                 {Title: "1",Id:1},
		{Title: "2",Id:2}
}
var expired = time.Hour * 24 * 7

reids.Set(ctx,key,value,expired)

err:

can't marshal []*Article (implement encoding.BinaryMarshaler)

do I need to serialize manually?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions