/
collection.go
78 lines (60 loc) · 1.91 KB
/
collection.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package gocb
import "time"
type kvTimeoutsConfig struct {
KVTimeout time.Duration
KVDurableTimeout time.Duration
}
// Collection represents a single collection.
type Collection struct {
collectionName string
scope string
bucket *Bucket
timeoutsConfig kvTimeoutsConfig
transcoder Transcoder
retryStrategyWrapper *retryStrategyWrapper
tracer requestTracer
useMutationTokens bool
getKvProvider func() (kvProvider, error)
}
func newCollection(scope *Scope, collectionName string) *Collection {
return &Collection{
collectionName: collectionName,
scope: scope.Name(),
bucket: scope.bucket,
timeoutsConfig: kvTimeoutsConfig{
KVTimeout: scope.timeoutsConfig.KVTimeout,
KVDurableTimeout: scope.timeoutsConfig.KVDurableTimeout,
},
transcoder: scope.transcoder,
retryStrategyWrapper: scope.retryStrategyWrapper,
tracer: scope.tracer,
useMutationTokens: scope.useMutationTokens,
getKvProvider: scope.getKvProvider,
}
}
func (c *Collection) name() string {
return c.collectionName
}
// ScopeName returns the name of the scope to which this collection belongs.
// UNCOMMITTED: This API may change in the future.
func (c *Collection) ScopeName() string {
return c.scope
}
// Bucket returns the name of the bucket to which this collection belongs.
// UNCOMMITTED: This API may change in the future.
func (c *Collection) Bucket() *Bucket {
return c.bucket
}
// Name returns the name of the collection.
func (c *Collection) Name() string {
return c.collectionName
}
func (c *Collection) startKvOpTrace(operationName string, tracectx requestSpanContext) requestSpan {
return c.tracer.StartSpan(operationName, tracectx).
SetTag("couchbase.bucket", c.bucket).
SetTag("couchbase.collection", c.collectionName).
SetTag("couchbase.service", "kv")
}
func (c *Collection) bucketName() string {
return c.bucket.Name()
}