-
Notifications
You must be signed in to change notification settings - Fork 0
/
uuid.go
60 lines (55 loc) · 1.13 KB
/
uuid.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
package convpb
import (
"github.com/google/uuid"
"google.golang.org/protobuf/types/known/wrapperspb"
)
type UUIDWrapper interface {
Commoner[UUIDWrapper]
CondSetNil(cond uuid.UUID) UUIDWrapper
ToStringValue() *wrapperspb.StringValue
ToString() string
}
type uuidWrapper struct {
value uuid.NullUUID
}
func (s *uuidWrapper) IsNil() bool {
return s == nil || !s.value.Valid
}
func (s *uuidWrapper) Clone() UUIDWrapper {
if s.IsNil() {
return &uuidWrapper{}
}
var c uuid.UUID
copy(c[:], s.value.UUID[:])
return &uuidWrapper{value: uuid.NullUUID{UUID: c, Valid: true}}
}
func (s *uuidWrapper) EmptySetNil() UUIDWrapper {
if s.IsNil() {
return s
}
if s.value.UUID == uuid.Nil {
s.value = uuid.NullUUID{}
}
return s
}
func (s *uuidWrapper) CondSetNil(cond uuid.UUID) UUIDWrapper {
if s.IsNil() {
return s
}
if s.value.UUID == cond {
s.value = uuid.NullUUID{}
}
return s
}
func (s *uuidWrapper) ToStringValue() *wrapperspb.StringValue {
if s.IsNil() {
return nil
}
return wrapperspb.String(s.value.UUID.String())
}
func (s *uuidWrapper) ToString() string {
if s.IsNil() {
return ""
}
return s.value.UUID.String()
}