1package gocb
2
3import "time"
4
5type kvTimeoutsConfig struct {
6	KVTimeout        time.Duration
7	KVDurableTimeout time.Duration
8}
9
10// Collection represents a single collection.
11type Collection struct {
12	collectionName string
13	scope          string
14	bucket         *Bucket
15
16	timeoutsConfig kvTimeoutsConfig
17
18	transcoder           Transcoder
19	retryStrategyWrapper *retryStrategyWrapper
20	tracer               requestTracer
21
22	useMutationTokens bool
23
24	getKvProvider func() (kvProvider, error)
25}
26
27func newCollection(scope *Scope, collectionName string) *Collection {
28	return &Collection{
29		collectionName: collectionName,
30		scope:          scope.Name(),
31		bucket:         scope.bucket,
32
33		timeoutsConfig: scope.timeoutsConfig,
34
35		transcoder:           scope.transcoder,
36		retryStrategyWrapper: scope.retryStrategyWrapper,
37		tracer:               scope.tracer,
38
39		useMutationTokens: scope.useMutationTokens,
40
41		getKvProvider: scope.getKvProvider,
42	}
43}
44
45func (c *Collection) name() string {
46	return c.collectionName
47}
48
49// ScopeName returns the name of the scope to which this collection belongs.
50// UNCOMMITTED: This API may change in the future.
51func (c *Collection) ScopeName() string {
52	return c.scope
53}
54
55// Bucket returns the name of the bucket to which this collection belongs.
56// UNCOMMITTED: This API may change in the future.
57func (c *Collection) Bucket() *Bucket {
58	return c.bucket
59}
60
61// Name returns the name of the collection.
62func (c *Collection) Name() string {
63	return c.collectionName
64}
65
66func (c *Collection) startKvOpTrace(operationName string, tracectx requestSpanContext) requestSpan {
67	return c.tracer.StartSpan(operationName, tracectx).
68		SetTag("couchbase.bucket", c.bucket).
69		SetTag("couchbase.collection", c.collectionName).
70		SetTag("couchbase.service", "kv")
71}
72
73func (c *Collection) bucketName() string {
74	return c.bucket.Name()
75}
76