Skip to content

Commit

Permalink
Merge pull request #1 from butonic/NatsjskvWatcher
Browse files Browse the repository at this point in the history
do not try to unmarshal on deletes
  • Loading branch information
kobergj authored Aug 7, 2024
2 parents 2e3020b + 8b872ec commit f62bb67
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions v4/store/nats-js-kv/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,21 +369,22 @@ func (n *natsStore) WatchAll(bucket string, opts ...nats.WatchOpt) (<-chan *Stor
}

var action string
var kv KeyValueEnvelope
switch u.Operation() {
default:
action = u.Operation().String()
case nats.KeyValuePut:
action = "create"
if err := json.Unmarshal(u.Value(), &kv); err != nil {
continue
}
case nats.KeyValueDelete:
action = "delete"
fallthrough
case nats.KeyValuePurge:
action = "delete"
kv = KeyValueEnvelope{
Key: n.NewKey(n.opts.Table, "", u.Key()).MicroKey(),
}
}

var kv KeyValueEnvelope
if err := json.Unmarshal(u.Value(), &kv); err != nil {
continue
}
ch <- &StoreUpdate{
Value: kv,
Action: action,
Expand Down

0 comments on commit f62bb67

Please sign in to comment.