-
Notifications
You must be signed in to change notification settings - Fork 43
/
sort_order.go
47 lines (40 loc) · 991 Bytes
/
sort_order.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
package search
import (
"errors"
"fmt"
"github.com/aliyun/aliyun-tablestore-go-sdk/v5/tablestore/otsprotocol"
)
type SortOrder int8
const (
SortOrder_ASC SortOrder = 0
SortOrder_DESC SortOrder = 1
)
func (x SortOrder) Enum() *SortOrder {
p := new(SortOrder)
*p = x
return p
}
func (o *SortOrder) ProtoBuffer() (*otsprotocol.SortOrder, error) {
if o == nil {
return nil, errors.New("sort order is nil")
}
if *o == SortOrder_ASC {
return otsprotocol.SortOrder_SORT_ORDER_ASC.Enum(), nil
} else if *o == SortOrder_DESC {
return otsprotocol.SortOrder_SORT_ORDER_DESC.Enum(), nil
} else {
return nil, errors.New("unknown sort order: " + fmt.Sprintf("%#v", *o))
}
}
func ParseSortOrder(order *otsprotocol.SortOrder) *SortOrder {
if order == nil {
return nil
}
if *order == otsprotocol.SortOrder_SORT_ORDER_ASC {
return SortOrder_ASC.Enum()
} else if *order == otsprotocol.SortOrder_SORT_ORDER_DESC {
return SortOrder_DESC.Enum()
} else {
return nil
}
}