mirror of
https://github.com/taigrr/nats.docs
synced 2025-01-18 04:03:23 -08:00
Merge pull request #18 from philpennock/patch-1
structured data: Go: handle decode errors
This commit is contained in:
commit
1adc0271aa
@ -7,7 +7,14 @@ For example, to receive JSON you could do:
|
||||
{% tabs %}
|
||||
{% tab title="Go" %}
|
||||
```go
|
||||
nc, err := nats.Connect("demo.nats.io")
|
||||
nc, err := nats.Connect("demo.nats.io",
|
||||
nats.ErrorHandler(func(nc *nats.Conn, s *nats.Subscription, err error) {
|
||||
if s != nil {
|
||||
log.Printf("Async error in %q/%q: %v", s.Subject, s.Queue, err)
|
||||
} else {
|
||||
log.Printf("Async error outside subscription: %v", err)
|
||||
}
|
||||
}))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -28,6 +35,9 @@ wg := sync.WaitGroup{}
|
||||
wg.Add(1)
|
||||
|
||||
// Subscribe
|
||||
// Decoding errors will be passed to the function supplied via
|
||||
// nats.ErrorHandler above, and the callback supplied here will
|
||||
// not be invoked.
|
||||
if _, err := ec.Subscribe("updates", func(s *stock) {
|
||||
log.Printf("Stock: %s - Price: %v", s.Symbol, s.Price)
|
||||
wg.Done()
|
||||
|
Loading…
x
Reference in New Issue
Block a user