-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiquery_example_test.go
More file actions
49 lines (38 loc) · 975 Bytes
/
multiquery_example_test.go
File metadata and controls
49 lines (38 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) 2020, Mohlmann Solutions SRL. All rights reserved.
// Use of this source code is governed by a License that can be found in the LICENSE file.
// SPDX-License-Identifier: BSD-3-Clause
package multidb
import (
"context"
"database/sql"
"errors"
"log"
"sync"
)
func ExampleErrCallbackFunc() {
var (
// ErrCallBackFunc is called concurrently.
// A Mutex is required when accessing a shared object
mu sync.Mutex
counters map[string]int
)
ecb := func(err error) {
// Ignore unimportant errors
if errors.Is(err, context.Canceled) ||
errors.Is(err, sql.ErrNoRows) ||
errors.Is(err, sql.ErrTxDone) {
return
}
nodeErr := new(NodeError)
if !errors.As(err, &nodeErr) {
log.Printf("Unknown error: %v", err)
}
mu.Lock()
counters[nodeErr.name]++
log.Printf("%v; fail count: %d", nodeErr, counters[nodeErr.name])
mu.Unlock()
}
mdb := new(MultiDB)
_, _ = mdb.MultiNode(3, ecb)
// Continue running queries
}