-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
59 lines (46 loc) · 866 Bytes
/
utils.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
package utils
import (
"time"
"github.com/google/uuid"
)
// PtrInt returns a pointer to an int.
func PtrInt(i int) *int {
return &i
}
// IntPtr returns a pointer to an int.
func IntPtr(i *int) int {
if i == nil {
return 0
}
return *i
}
// PtrUUID returns a pointer to a UUID.
func PtrUUID(u uuid.UUID) *uuid.UUID {
return &u
}
// StrPtr returns a pointer to a string.
func StrPtr(s string) *string {
return &s
}
// PtrStr returns a pointer to a string.
func PtrStr(s *string) string {
if s == nil {
return ""
}
return *s
}
// PtrTime returns a pointer to a time.
func PtrTime(t time.Time) *time.Time {
return &t
}
// TimePtr returns a pointer to a time.
func TimePtr(t *time.Time) time.Time {
if t == nil {
return time.Time{}
}
return *t
}
// UUIDPtr returns a pointer to a UUID.
func UUIDPtr(u *uuid.UUID) uuid.UUID {
return *u
}