forked from swxctx/gutil
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpointer.go
75 lines (61 loc) · 839 Bytes
/
pointer.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package gutil
import (
"time"
)
func StringPtr(s string) *string {
return &s
}
func BoolPtr(i bool) *bool {
return &i
}
func BytePtr(i byte) *byte {
return &i
}
func Int32Ptr(i int32) *int32 {
return &i
}
func Int64Ptr(i int64) *int64 {
return &i
}
func Float64Ptr(i float64) *float64 {
return &i
}
func TimePtr(t time.Time) *time.Time {
return &t
}
func PtrString(s *string) string {
if s == nil {
return ""
}
return *s
}
func PtrBool(i *bool) bool {
if i == nil {
return false
}
return *i
}
func PtrByte(i *byte) byte {
if i == nil {
return byte(0)
}
return *i
}
func PtrInt32(i *int32) int32 {
if i == nil {
return 0
}
return *i
}
func PtrInt64(i *int64) int64 {
if i == nil {
return 0
}
return *i
}
func PtrFloat64(i *float64) float64 {
if i == nil {
return float64(0)
}
return *i
}