-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6131577
commit 22a3660
Showing
6 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func test() int { | ||
i := 0 | ||
defer func() { | ||
fmt.Println("defer1") | ||
}() | ||
defer func() { | ||
i += 1 | ||
fmt.Println("defer2") | ||
}() | ||
return i | ||
} | ||
|
||
func main() { | ||
// Output: | ||
// defer2 | ||
// defer1 | ||
// return 0 | ||
fmt.Println("return", test()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module hello | ||
|
||
go 1.17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
const ( | ||
RED = iota | ||
GREEN | ||
BLUE | ||
) | ||
|
||
func main() { | ||
// 赋值 | ||
var a int = 10 | ||
fmt.Println(a) | ||
|
||
// 指针 | ||
var p *int = &a | ||
*p = 11 | ||
fmt.Println(a) | ||
|
||
// Rune -> int32 | ||
fmt.Println(len("🍉🍇🍑🍓🥝")) | ||
fmt.Println(len([]rune("🍉🍇🍑🍓🥝"))) | ||
|
||
// map | ||
var o = map[string]int{ | ||
"a": 3, | ||
"b": 4, | ||
} | ||
fmt.Println(o) | ||
|
||
// 判断是否存在某个 key | ||
if v, ok := o["a"]; ok { | ||
fmt.Println("a exist", v) | ||
} | ||
|
||
fmt.Println(RED) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func hello() { | ||
fmt.Println("hello, shanyue") | ||
} | ||
|
||
func main() { | ||
hello() | ||
go hello() | ||
fmt.Println("main function") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters