1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-05-31 21:59:42 +02:00

add store encode/decode for record

This commit is contained in:
asim 2025-05-04 20:13:58 +01:00
parent 484eb3d15e
commit 60474ed38f

View File

@ -60,6 +60,21 @@ func NewRecord(key string, val interface{}) *Record {
}
}
// Encode will marshal any type into the byte Value field
func (r *Record) Encode(v interface{}) error {
b, err := json.Marshal(v)
if err != nil {
return err
}
r.Value = b
return nil
}
// Decode is a convenience helper for decoding records
func (r *Record) Decode(v interface{}) error {
return json.Unmarshal(r.Value, v)
}
// Read records
func Read(key string, opts ...ReadOption) ([]*Record, error) {
// execute the query