etcd_tools/pair.go

34 lines
635 B
Go
Raw Permalink Normal View History

2018-04-12 12:10:17 -05:00
package etcd_tools
import (
"encoding/json"
2019-05-17 09:02:50 -05:00
"github.com/coreos/etcd/mvcc/mvccpb"
2018-04-12 12:10:17 -05:00
)
type Pair struct {
Key string
Value string
Bytes []byte
Created int64
Modified int64
Version int64
Lease int64
}
func NewPair(kv *mvccpb.KeyValue) *Pair {
return &Pair{string(kv.Key), string(kv.Value), kv.Value, kv.CreateRevision, kv.ModRevision, kv.Version, kv.Lease}
}
func Pairs(kvs []*mvccpb.KeyValue) []*Pair {
result := make([]*Pair, 0, len(kvs))
for _, kv := range kvs {
result = append(result, NewPair(kv))
}
return result
}
func (p *Pair) Fill(v *interface{}) error {
return json.Unmarshal(p.Bytes, v)
}