Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f4a1937

Browse files
Update 设计模式.md
1 parent b23d8d7 commit f4a1937

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

设计模式.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# 设计模式
22

3-
1. 责任链模式
3+
4+
5+
## 责任链模式
46

57
```go
68
package main
@@ -49,3 +51,32 @@ func main() {
4951

5052
```
5153

54+
55+
56+
57+
58+
## 单例模式
59+
60+
```go
61+
package main
62+
63+
import "sync"
64+
65+
type people struct {
66+
}
67+
68+
var instance *people
69+
var once sync.Once
70+
71+
func getInstance() *people {
72+
once.Do(func() {
73+
instance = &people{}
74+
})
75+
return instance
76+
}
77+
78+
func main() {
79+
80+
}
81+
```
82+

0 commit comments

Comments
 (0)