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:
parent
484eb3d15e
commit
60474ed38f
@ -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
|
// Read records
|
||||||
func Read(key string, opts ...ReadOption) ([]*Record, error) {
|
func Read(key string, opts ...ReadOption) ([]*Record, error) {
|
||||||
// execute the query
|
// execute the query
|
||||||
|
Loading…
x
Reference in New Issue
Block a user