/
partition_key.go
45 lines (38 loc) · 1.06 KB
/
partition_key.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package azcosmos
import "encoding/json"
// PartitionKey represents a logical partition key value.
type PartitionKey struct {
isNone bool
partitionKeyInternal *partitionKeyInternal
}
// NewPartitionKeyNone creates a partition key value for non-partitioned containers.
func NewPartitionKeyNone() *PartitionKey {
return &PartitionKey{
isNone: true,
partitionKeyInternal: nonePartitionKey,
}
}
// NewPartitionKey creates a new partition key.
// value - the partition key value.
func NewPartitionKey(value interface{}) (*PartitionKey, error) {
pkInternal, err := newPartitionKeyInternal([]interface{}{value})
if err != nil {
return nil, err
}
return &PartitionKey{
partitionKeyInternal: pkInternal,
isNone: false,
}, nil
}
func (pk *PartitionKey) toJsonString() (string, error) {
if pk.isNone {
return "", nil
}
res, err := json.Marshal(pk.partitionKeyInternal)
if err != nil {
return "", err
}
return string(res), nil
}