diff --git a/README.md b/README.md index c4cd6c2..8406363 100644 --- a/README.md +++ b/README.md @@ -73,8 +73,9 @@ $ go get github.com/Tinywan/golang-tutorial ### 34 - 反射 ### [35 - 读文件](/docs/golang_tutorial_35.md) -## 其他文档 - -* [如何编写Go代码](/docs/how_to_write_go_code.md) +## 文档 +* [Go 零基础编程入门教程](http://go-courses.tinywan.com/_book/) +* [Go 语言标准库](http://go-library.tinywan.com/_book/) +* [如何编写 Go代码](/docs/how_to_write_go_code.md) * [原文](https://golangbot.com/) diff --git a/demo/channel/demo01.go b/demo/channel/demo01.go new file mode 100644 index 0000000..7905807 --- /dev/null +++ b/demo/channel/demo01.go @@ -0,0 +1,5 @@ +package main + +func main() { + +} diff --git a/demo/point/demo.go b/demo/point/demo.go index 4cc7303..cbc98f5 100644 --- a/demo/point/demo.go +++ b/demo/point/demo.go @@ -4,9 +4,16 @@ import ( "fmt" ) -func main(){ +func main() { b := 255 var a = &b - fmt.Printf("Type of a is %T\n",a) - fmt.Println("address of b is",a) -} \ No newline at end of file + fmt.Printf("Type of a is %T\n", a) + fmt.Println("address of b is", a) + + s := map[string]int{"age": 24} + var t map[string]string // 正确 + t1 := map[string]string // 错误 + fmt.Println(s) + fmt.Println(t) + fmt.Println(t1) +} diff --git a/demo/point/dmoe002.go b/demo/point/dmoe002.go new file mode 100644 index 0000000..5660b48 --- /dev/null +++ b/demo/point/dmoe002.go @@ -0,0 +1,47 @@ +package main + +import ( + "fmt" + "reflect" +) + +// import ( +// "fmt" +// ) go_basic_courses + +func main() { + // 声明一个集合字典,默认为空 + a := 15 + fmt.Println("address of b is ", a) + fmt.Println("address of b is ", &a) + m := map[string]int{} + fmt.Println("address of b i is ", m) + fmt.Printf("Type of a is %T\n", m) + fmt.Printf("m值是 %v \n", m == nil) + var dir map[string]string + fmt.Printf("dir字典的值是: | %v \n", dir) + fmt.Printf("dir字典是否为nil | %v \n", dir == nil) + // nil map不能赋值,如果直接赋值会报错:“panic: assignment to entry in nil map”,下面语句将会报错 + // dir["name"] = "Tinywan" + + fmt.Println("----------------------------") + // 使用make函数进行初始化创建一个非nil的map + dir = make(map[string]string) + // map是引用类型,未初始化的是指向nil,初始化了以后应该就有自己的内存空间了,所以不是nil + fmt.Printf("dir字典的值是: | %v \n", dir) + fmt.Printf("dir字典是否为nil | %v \n", dir == nil) + + fmt.Println("----------------------------") + // make之后分配内存了,一旦分配了内存地址就不为空了,可以赋值了 + dir["name"] = "Tinywan" + fmt.Printf("dir字典的键:值 |%v \n", dir) + fmt.Printf("dir字典的类型 |%v \n", reflect.TypeOf(dir)) + fmt.Printf("name的值是 |%v \n", dir["name"]) + // value, ok := s["ok"] + // if ok == nil { + // s := make(map[string]int) + // s["ok"] = 19 + // fmt.Println(s["ok"]) + // } + // fmt.Println(s["ok"]) +}