File tree 3 files changed +64
-1
lines changed
3 files changed +64
-1
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ package main
93
93
94
94
import (
95
95
" fmt"
96
- pointer " github.com/golang-infrastructure/go-reflect-utils "
96
+ " github.com/golang-infrastructure/go-pointer "
97
97
)
98
98
99
99
func main () {
@@ -128,6 +128,19 @@ func main() {
128
128
// 返回当前时间的指针
129
129
nowPointer := pointer.Now ()
130
130
fmt.Println (nowPointer) // Output: 2023-05-30 11:46:20.3695476 +0800 CST m=+0.003922101
131
+
132
+ // atomic.Bool指针 - true
133
+ atomicTruePointer := pointer.AtomicTruePointer ()
134
+ fmt.Println (atomicTruePointer) // Output: &{{} 1}
135
+
136
+ // atomic.Bool指针 - false
137
+ atomicFalsePointer := pointer.AtomicFalsePointer ()
138
+ fmt.Println (atomicFalsePointer) // Output: &{{} 0}
139
+
140
+ // atomic.Int64指针
141
+ int64Pointer := pointer.AtomicInt64Pointer (128 )
142
+ fmt.Println (int64Pointer) // Output: &{{} {} 128}
143
+
131
144
}
132
145
```
133
146
Original file line number Diff line number Diff line change @@ -37,4 +37,17 @@ func main() {
37
37
// 返回当前时间的指针
38
38
nowPointer := pointer .Now ()
39
39
fmt .Println (nowPointer ) // Output: 2023-05-30 11:46:20.3695476 +0800 CST m=+0.003922101
40
+
41
+ // atomic.Bool指针 - true
42
+ atomicTruePointer := pointer .AtomicTruePointer ()
43
+ fmt .Println (atomicTruePointer ) // Output: &{{} 1}
44
+
45
+ // atomic.Bool指针 - false
46
+ atomicFalsePointer := pointer .AtomicFalsePointer ()
47
+ fmt .Println (atomicFalsePointer ) // Output: &{{} 0}
48
+
49
+ // atomic.Int64指针
50
+ int64Pointer := pointer .AtomicInt64Pointer (128 )
51
+ fmt .Println (int64Pointer ) // Output: &{{} {} 128}
52
+
40
53
}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package pointer
2
2
3
3
import (
4
4
reflectutils "github.com/golang-infrastructure/go-reflect-utils"
5
+ "sync/atomic"
5
6
"time"
6
7
)
7
8
@@ -50,3 +51,39 @@ func FromPointerOrDefault[T any](valuePointer *T, defaultValue T) T {
50
51
return * valuePointer
51
52
}
52
53
}
54
+
55
+ func AtomicTruePointer () * atomic.Bool {
56
+ b := & atomic.Bool {}
57
+ b .Store (true )
58
+ return b
59
+ }
60
+
61
+ func AtomicFalsePointer () * atomic.Bool {
62
+ b := & atomic.Bool {}
63
+ b .Store (false )
64
+ return b
65
+ }
66
+
67
+ func AtomicUInt64Pointer (value uint64 ) * atomic.Uint64 {
68
+ i := & atomic.Uint64 {}
69
+ i .Store (value )
70
+ return i
71
+ }
72
+
73
+ func AtomicUInt32Pointer (value uint32 ) * atomic.Uint32 {
74
+ i := & atomic.Uint32 {}
75
+ i .Store (value )
76
+ return i
77
+ }
78
+
79
+ func AtomicInt64Pointer (value int64 ) * atomic.Int64 {
80
+ i := & atomic.Int64 {}
81
+ i .Store (value )
82
+ return i
83
+ }
84
+
85
+ func AtomicInt32Pointer (value int32 ) * atomic.Int32 {
86
+ i := & atomic.Int32 {}
87
+ i .Store (value )
88
+ return i
89
+ }
You can’t perform that action at this time.
0 commit comments