feat(Go-StudyExample): 新增 网络及端口测试、传值和传址的比较、切片测试、Map测试、通道测试、测试init调用、测试error、defer关键字、recover测试、测试携程的异常捕获、矩阵旋转

This commit is contained in:
huangzj
2020-07-13 17:02:04 +08:00
parent f5894a2680
commit 9ad10e8cd9
12 changed files with 514 additions and 13 deletions
+39
View File
@@ -0,0 +1,39 @@
/*
* @Author : huangzj
* @Time : 2020/7/13 14:22
* @Description
*/
package originGoLanguage
import "fmt"
func TestMap() {
//没有初始化的是nil,不能进行赋值
var countryMap1 map[string]string
fmt.Println(countryMap1 == nil)
countryMap := make(map[string]string)
countryMap["a"] = "aCountry"
countryMap["b"] = "bCountry"
countryMap["c"] = "cCountry"
countryMap["d"] = "dCountry"
for key, value := range countryMap {
fmt.Println(key + " is " + value)
}
//获取Map的值
mValue, ok := countryMap["a"]
fmt.Println(ok, mValue)
mValue1, ok1 := countryMap["aaaa"]
fmt.Println(ok1, mValue1)
//删除map中的元素
delete(countryMap, "a")
delete(countryMap, "b")
for key, value := range countryMap {
fmt.Println(key + " is " + value)
}
}