We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 8edb090 + 389a39a commit b8a5c11Copy full SHA for b8a5c11
Roadmap/23 - SINGLETON/go/kodenook.go
@@ -0,0 +1,34 @@
1
+package main
2
+
3
+import (
4
+ "fmt"
5
+ "sync"
6
+)
7
8
+type Singleton struct {
9
+ data string
10
+}
11
12
+var instancia *Singleton
13
14
+var once sync.Once
15
16
+func GetInstance() *Singleton {
17
+ once.Do(func() {
18
+ instancia = &Singleton{data: "Data example"}
19
+ })
20
+ return instancia
21
22
23
+func main() {
24
25
+ singleton := GetInstance()
26
+ fmt.Println(singleton.data)
27
28
+ other := GetInstance()
29
+ fmt.Println(other.data)
30
31
+ singleton.data = "New data"
32
33
34
0 commit comments