└── go.introduce ├── chapter09 ├── code09 │ ├── cpu.prof │ ├── mem.out │ ├── trace.out │ ├── server.go │ ├── .vscode │ │ └── launch.json │ ├── trace.go │ └── console.go ├── code08 │ ├── cpu.out │ ├── cpu.svg │ ├── mem.out │ ├── mem.svg │ ├── code08.test.exe │ ├── usage.txt │ ├── counter_test.go │ ├── .vscode │ │ └── launch.json │ └── counter.go ├── code01 │ ├── onecore │ │ └── coffeemachine.go │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code07 │ ├── main.go │ ├── main4.go │ ├── main2.go │ ├── main3.go │ └── .vscode │ │ └── launch.json ├── code04 │ ├── main2.go │ ├── main3.go │ ├── main.go │ ├── main4.go │ ├── main5.go │ ├── main6.go │ └── .vscode │ │ └── launch.json ├── code02 │ ├── onecore │ │ └── coffeemachine.go │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code03 │ ├── parallel │ │ └── coffeemachine.go │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code05 │ ├── main3.go │ ├── main6.go │ ├── main2.go │ ├── main4.go │ ├── main5.go │ ├── main7.go │ ├── main.go │ ├── .vscode │ │ └── launch.json │ └── main8.go ├── code10 │ ├── mapreduce │ │ ├── mapworker.go │ │ ├── reduceworker.go │ │ ├── master.go │ │ ├── init.go │ │ ├── sumreduce.go │ │ ├── mapreduce.go │ │ └── inputsplit.go │ ├── main.go │ └── .vscode │ │ └── launch.json └── code06 │ ├── main.go │ ├── main4.go │ ├── .vscode │ └── launch.json │ ├── main7.go │ ├── main2.go │ ├── main6.go │ ├── main5.go │ └── main3.go ├── chapter08 ├── code02 │ ├── hello.txt │ ├── hello2.txt │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code06 │ ├── hello.txt │ └── .vscode │ │ └── launch.json ├── code10 │ ├── dir02 │ │ └── hello2.txt │ ├── dir01 │ │ └── dir0101 │ │ │ └── hello.txt │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code05 │ ├── hello.txt │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code01 │ ├── hello.txt │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code03 │ ├── hello.txt │ ├── hello2.txt │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code07 │ ├── hello.txt │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code04 │ ├── hello.txt │ ├── hello2.txt │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code08 │ ├── hello.txt │ └── .vscode │ │ └── launch.json ├── code11 │ ├── config.property │ ├── main.go │ ├── .vscode │ │ └── launch.json │ └── property │ │ └── property.go └── code09 │ └── .vscode │ └── launch.json ├── chapter12 ├── ChatClient │ ├── .vs │ │ └── ChatClient │ │ │ └── v15 │ │ │ ├── Server │ │ │ └── sqlite3 │ │ │ │ ├── db.lock │ │ │ │ └── storage.ide │ │ │ └── .suo │ └── ChatClient │ │ ├── obj │ │ └── Debug │ │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ │ │ ├── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs │ │ │ ├── ChatClient.csproj.CoreCompileInputs.cache │ │ │ ├── ChatClient.exe │ │ │ ├── ChatClient.pdb │ │ │ ├── ChatClient.FrmChat.resources │ │ │ ├── ChatClient.csproj.GenerateResource.cache │ │ │ ├── ChatClient.csprojAssemblyReference.cache │ │ │ ├── ChatClient.Properties.Resources.resources │ │ │ ├── DesignTimeResolveAssemblyReferences.cache │ │ │ ├── ChatClient.csprojResolveAssemblyReference.cache │ │ │ └── DesignTimeResolveAssemblyReferencesInput.cache │ │ ├── bin │ │ └── Debug │ │ │ ├── ChatClient.exe │ │ │ ├── ChatClient.pdb │ │ │ └── ChatClient.exe.config │ │ ├── App.config │ │ ├── Properties │ │ └── Settings.settings │ │ └── Program.cs ├── ChatClient.exe ├── ChatClient.rar ├── chat │ ├── server │ │ ├── userInfo.go │ │ ├── broadcast.go │ │ ├── connWrite.go │ │ └── init.go │ └── .vscode │ │ └── launch.json └── mysql.sql ├── chapter02 ├── code05 │ ├── app │ │ ├── config │ │ │ └── config.go │ │ └── app.go │ ├── .vscode │ │ └── settings.rar │ └── code05.go ├── code06 │ ├── app │ │ ├── b.go │ │ ├── a.go │ │ └── config │ │ │ └── config.go │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code01 │ └── test.go ├── code03 │ └── code03.go ├── code07 │ ├── bool.go │ ├── opt_note.go │ ├── var2.go │ ├── enum.go │ ├── const.go │ ├── opt_other.go │ ├── opt_logic.go │ ├── num.go │ ├── str.go │ ├── var.go │ ├── .vscode │ │ └── launch.json │ ├── type_convert.go │ ├── opt_bit.go │ └── opt_num.go ├── code02 │ └── code02.go ├── code04 │ └── code04.go └── code08 │ ├── .vscode │ └── launch.json │ └── main.go ├── chapter10 ├── code01 │ ├── value.txt │ ├── type.txt │ └── .vscode │ │ └── launch.json ├── code10 │ ├── ydorm │ │ ├── table.go │ │ └── field.go │ ├── entity │ │ └── student.go │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code05 │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code02 │ └── .vscode │ │ └── launch.json ├── code03 │ └── .vscode │ │ └── launch.json ├── code04 │ └── .vscode │ │ └── launch.json ├── code06 │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code07 │ └── .vscode │ │ └── launch.json ├── code08 │ └── .vscode │ │ └── launch.json └── code09 │ ├── .vscode │ └── launch.json │ └── main.go ├── chapter06 ├── code05 │ ├── entity │ │ └── student.go │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code06 │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code03 │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code04 │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code09 │ ├── linklist │ │ ├── linklist_find.go │ │ ├── listnode.go │ │ ├── linklist_insert.go │ │ ├── linklist.go │ │ └── linklist_delete.go │ └── .vscode │ │ └── launch.json ├── code07 │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code02 │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code01 │ ├── .vscode │ │ └── launch.json │ └── main.go └── code08 │ └── .vscode │ └── launch.json ├── chapter01 ├── code01 │ ├── hello.o │ ├── hello.exe │ ├── linux-main │ ├── mac-main │ ├── hello.go │ └── hello_vet.go ├── code02 │ ├── main.go │ └── .vscode │ │ └── launch.json └── cmd.txt ├── chapter07 ├── code03 │ ├── entity │ │ ├── mycar.go │ │ ├── idrive.go │ │ ├── bmw.go │ │ └── aodi.go │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code07 │ ├── sql │ │ ├── ibuilder.go │ │ ├── dbdata.go │ │ ├── dbtype.go │ │ └── orderby.go │ └── .vscode │ │ └── launch.json ├── code06 │ ├── entity │ │ ├── iduck.go │ │ ├── factory.go │ │ ├── duck.go │ │ └── goose.go │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code02 │ ├── entity │ │ ├── person.go │ │ └── student.go │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code01 │ ├── main.go │ ├── .vscode │ │ └── launch.json │ └── entity │ │ └── person.go ├── code04 │ ├── .vscode │ │ └── launch.json │ └── main.go └── code05 │ ├── .vscode │ └── launch.json │ └── main.go ├── chapter11 ├── code06 │ ├── server │ │ ├── images │ │ │ └── avatar5.png │ │ ├── web │ │ │ ├── reqdata.go │ │ │ └── resdata.go │ │ ├── font │ │ │ └── font-awesome │ │ │ │ ├── less │ │ │ │ ├── screen-reader.less │ │ │ │ ├── fixed-width.less │ │ │ │ ├── larger.less │ │ │ │ ├── list.less │ │ │ │ ├── core.less │ │ │ │ ├── stacked.less │ │ │ │ ├── font-awesome.less │ │ │ │ ├── bordered-pulled.less │ │ │ │ ├── rotated-flipped.less │ │ │ │ ├── path.less │ │ │ │ └── animated.less │ │ │ │ ├── scss │ │ │ │ ├── _fixed-width.scss │ │ │ │ ├── _screen-reader.scss │ │ │ │ ├── _larger.scss │ │ │ │ ├── _list.scss │ │ │ │ ├── _core.scss │ │ │ │ ├── font-awesome.scss │ │ │ │ ├── _stacked.scss │ │ │ │ ├── _bordered-pulled.scss │ │ │ │ ├── _rotated-flipped.scss │ │ │ │ └── _path.scss │ │ │ │ ├── fonts │ │ │ │ ├── FontAwesome.otf │ │ │ │ ├── fontawesome-webfont.eot │ │ │ │ ├── fontawesome-webfont.ttf │ │ │ │ ├── fontawesome-webfont.woff │ │ │ │ └── fontawesome-webfont.woff2 │ │ │ │ └── HELP-US-OUT.txt │ │ ├── error.html │ │ ├── css │ │ │ └── index.css │ │ └── server.go │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code02 │ ├── index.html │ ├── server.go │ └── .vscode │ │ └── launch.json ├── code03 │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code05 │ ├── sse │ │ └── sse.go │ ├── index.html │ └── .vscode │ │ └── launch.json ├── code01 │ ├── .vscode │ │ └── launch.json │ ├── server │ │ └── server.go │ └── main.go └── code04 │ └── .vscode │ └── launch.json ├── chapter05 ├── code23 │ ├── ydbase │ │ ├── config.go │ │ ├── login.go │ │ └── table.go │ └── .vscode │ │ └── launch.json ├── code01 │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code18 │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code11 │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code17 │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code02 │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code10 │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code08 │ ├── main.go │ ├── .vscode │ │ └── launch.json │ ├── main3.go │ └── main2.go ├── code12 │ ├── main.go │ └── .vscode │ │ └── launch.json ├── code03 │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code04 │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code05 │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code06 │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code07 │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code09 │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code13 │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code14 │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code15 │ ├── .vscode │ │ └── launch.json │ ├── main2.go │ └── main.go ├── code16 │ └── .vscode │ │ └── launch.json ├── code19 │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code20 │ ├── .vscode │ │ └── launch.json │ └── main.go ├── code21 │ ├── .vscode │ │ └── launch.json │ └── main.go └── code22 │ ├── .vscode │ └── launch.json │ └── main.go ├── chapter03 ├── code05 │ ├── func.go │ └── .vscode │ │ └── launch.json ├── code08 │ ├── func.go │ ├── func2.go │ └── .vscode │ │ └── launch.json ├── code01 │ ├── func01.go │ └── .vscode │ │ └── launch.json ├── code02 │ ├── func02.go │ └── .vscode │ │ └── launch.json ├── code11 │ ├── func2.go │ ├── func.go │ └── .vscode │ │ └── launch.json ├── code06 │ ├── func.go │ └── .vscode │ │ └── launch.json ├── code10 │ ├── func.go │ └── .vscode │ │ └── launch.json ├── code07 │ ├── func.go │ └── .vscode │ │ └── launch.json ├── code03 │ ├── func03.go │ └── .vscode │ │ └── launch.json ├── code12 │ ├── main.go │ ├── calc │ │ └── calc.go │ └── .vscode │ │ └── launch.json ├── code09 │ ├── func.go │ └── .vscode │ │ └── launch.json └── code04 │ ├── func.go │ └── .vscode │ └── launch.json └── chapter04 ├── code01 ├── main.go └── .vscode │ └── launch.json ├── code08 ├── main.go └── .vscode │ └── launch.json ├── code03 ├── main.go └── .vscode │ └── launch.json ├── code06 ├── main.go └── .vscode │ └── launch.json ├── code07 ├── main.go └── .vscode │ └── launch.json ├── code09 ├── main.go └── .vscode │ └── launch.json ├── code10 ├── main.go └── .vscode │ └── launch.json ├── code05 ├── main.go └── .vscode │ └── launch.json ├── code04 ├── main.go └── .vscode │ └── launch.json ├── code02 ├── .vscode │ └── launch.json └── main.go └── code11 └── .vscode └── launch.json /go.introduce/chapter09/code09/cpu.prof: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /go.introduce/chapter08/code02/hello.txt: -------------------------------------------------------------------------------- 1 | Hello Go -------------------------------------------------------------------------------- /go.introduce/chapter08/code02/hello2.txt: -------------------------------------------------------------------------------- 1 | 你好,Go语言! -------------------------------------------------------------------------------- /go.introduce/chapter08/code06/hello.txt: -------------------------------------------------------------------------------- 1 | Hello Go! -------------------------------------------------------------------------------- /go.introduce/chapter08/code10/dir02/hello2.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /go.introduce/chapter08/code05/hello.txt: -------------------------------------------------------------------------------- 1 | Hello Go2! -------------------------------------------------------------------------------- /go.introduce/chapter08/code10/dir01/dir0101/hello.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /go.introduce/chapter08/code01/hello.txt: -------------------------------------------------------------------------------- 1 | 你好,Go语言! 2 | Hello Go -------------------------------------------------------------------------------- /go.introduce/chapter08/code03/hello.txt: -------------------------------------------------------------------------------- 1 | Hello Go 2 | Hello Golang -------------------------------------------------------------------------------- /go.introduce/chapter08/code03/hello2.txt: -------------------------------------------------------------------------------- 1 | 你好,Go语言! 2 | Hello,GoLang! -------------------------------------------------------------------------------- /go.introduce/chapter08/code07/hello.txt: -------------------------------------------------------------------------------- 1 | Hello Go! 2 | 你好,TypeScript! 3 | -------------------------------------------------------------------------------- /go.introduce/chapter08/code04/hello.txt: -------------------------------------------------------------------------------- 1 | Hello Go 2 | Hello Java 3 | Hello C# -------------------------------------------------------------------------------- /go.introduce/chapter08/code04/hello2.txt: -------------------------------------------------------------------------------- 1 | 你好,Go语言! 2 | Hello Java 3 | Hello C# -------------------------------------------------------------------------------- /go.introduce/chapter08/code08/hello.txt: -------------------------------------------------------------------------------- 1 | Hello Go! 2 | 你好,TypeScript!222222 3 | -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/.vs/ChatClient/v15/Server/sqlite3/db.lock: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /go.introduce/chapter08/code11/config.property: -------------------------------------------------------------------------------- 1 | #配置文件 2 | db.uname=root 3 | db.pwd=123 4 | db.url=127.0.0.1 5 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code05/app/config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | //Cver 字符类型的版本信息 4 | var Cver = "1.0.0" 5 | -------------------------------------------------------------------------------- /go.introduce/chapter10/code01/value.txt: -------------------------------------------------------------------------------- 1 | type Value struct { 2 | typ *rtype 3 | ptr unsafe.Pointer 4 | flag 5 | } -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /go.introduce/chapter06/code05/entity/student.go: -------------------------------------------------------------------------------- 1 | package entity 2 | 3 | type Student struct { 4 | name string 5 | id int 6 | } 7 | -------------------------------------------------------------------------------- /go.introduce/chapter10/code01/type.txt: -------------------------------------------------------------------------------- 1 | 01 type Value struct { 2 | 02 typ *rtype 3 | 03 ptr unsafe.Pointer 4 | 04 flag 5 | 05 } -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/ChatClient.csproj.CoreCompileInputs.cache: -------------------------------------------------------------------------------- 1 | be32ffc2b69865816aed45938fb15704ddf004a5 2 | -------------------------------------------------------------------------------- /go.introduce/chapter01/code01/hello.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter01/code01/hello.o -------------------------------------------------------------------------------- /go.introduce/chapter09/code08/cpu.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter09/code08/cpu.out -------------------------------------------------------------------------------- /go.introduce/chapter09/code08/cpu.svg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter09/code08/cpu.svg -------------------------------------------------------------------------------- /go.introduce/chapter09/code08/mem.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter09/code08/mem.out -------------------------------------------------------------------------------- /go.introduce/chapter09/code08/mem.svg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter09/code08/mem.svg -------------------------------------------------------------------------------- /go.introduce/chapter09/code09/mem.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter09/code09/mem.out -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter12/ChatClient.exe -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter12/ChatClient.rar -------------------------------------------------------------------------------- /go.introduce/chapter01/code01/hello.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter01/code01/hello.exe -------------------------------------------------------------------------------- /go.introduce/chapter01/code01/linux-main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter01/code01/linux-main -------------------------------------------------------------------------------- /go.introduce/chapter01/code01/mac-main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter01/code01/mac-main -------------------------------------------------------------------------------- /go.introduce/chapter02/code06/app/b.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import "fmt" 4 | 5 | func init() { 6 | fmt.Println("app package b.go init()") 7 | } 8 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code03/entity/mycar.go: -------------------------------------------------------------------------------- 1 | package entity 2 | 3 | //MyCar 结构体组合IDrive接口 4 | type MyCar struct { 5 | IDrive //具备Drive的能力 6 | } 7 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code09/trace.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter09/code09/trace.out -------------------------------------------------------------------------------- /go.introduce/chapter09/code08/code08.test.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter09/code08/code08.test.exe -------------------------------------------------------------------------------- /go.introduce/chapter02/code05/.vscode/settings.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter02/code05/.vscode/settings.rar -------------------------------------------------------------------------------- /go.introduce/chapter01/code01/hello.go: -------------------------------------------------------------------------------- 1 | //必须有一个main包 2 | package main 3 | 4 | import ( 5 | "fmt" 6 | ) 7 | 8 | func main() { 9 | fmt.Println("Hello World") 10 | } 11 | -------------------------------------------------------------------------------- /go.introduce/chapter01/code01/hello_vet.go: -------------------------------------------------------------------------------- 1 | 2 | package main1 3 | 4 | import ( 5 | "fmt1" 6 | ) 7 | 8 | func main() 9 | { 10 | fmt.Println("Hello World") 11 | } 12 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code07/sql/ibuilder.go: -------------------------------------------------------------------------------- 1 | package sql 2 | 3 | //IBuilder 接口 4 | type IBuilder interface { 5 | GenSelect(*DbData) string 6 | GenPage(*DbData) string 7 | } 8 | -------------------------------------------------------------------------------- /go.introduce/chapter10/code10/ydorm/table.go: -------------------------------------------------------------------------------- 1 | package ydorm 2 | 3 | //TableInfo 表信息 4 | type TableInfo struct { 5 | Name string //表名 6 | Fields []FieldInfo //表字段信息 7 | } 8 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/images/avatar5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter11/code06/server/images/avatar5.png -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/web/reqdata.go: -------------------------------------------------------------------------------- 1 | package web 2 | 3 | //ReqData 请求数据格式 4 | type ReqData struct { 5 | token string 6 | api string 7 | data string 8 | } 9 | -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/.vs/ChatClient/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter12/ChatClient/.vs/ChatClient/v15/.suo -------------------------------------------------------------------------------- /go.introduce/chapter02/code01/test.go: -------------------------------------------------------------------------------- 1 | //和文件夹名code01一致 2 | package code01 3 | 4 | import "fmt" 5 | 6 | //大写首字母导出Hello函数 7 | func Hello() { 8 | fmt.Println("Hello world") 9 | } 10 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code03/entity/idrive.go: -------------------------------------------------------------------------------- 1 | package entity 2 | 3 | //IDrive 接口 4 | //只要实现了Drive(name string)方法即实现了IDrive 接口 5 | type IDrive interface { 6 | Drive(name string) 7 | } 8 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code06/entity/iduck.go: -------------------------------------------------------------------------------- 1 | package entity 2 | 3 | //IDuck 鸭子类型接口 4 | type IDuck interface { 5 | Sleep() 6 | Eat() 7 | SingGua() 8 | Type() string 9 | } 10 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code03/code03.go: -------------------------------------------------------------------------------- 1 | //包名demo和目录名code03不一致 2 | package demo 3 | 4 | import "fmt" 5 | 6 | //大写首字母导出Hello函数 7 | func Hello() { 8 | fmt.Println("Hello demo") 9 | } 10 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code01/onecore/coffeemachine.go: -------------------------------------------------------------------------------- 1 | package onecore 2 | 3 | //CoffeeMachine 咖啡机(共享1个) 4 | type CoffeeMachine struct { 5 | CoffeeName string 6 | Gopher //获取使用权的地鼠 7 | } 8 | -------------------------------------------------------------------------------- /go.introduce/chapter12/chat/server/userInfo.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | //userInfo用于存储用户信息 4 | type userInfo struct { 5 | name string 6 | perC chan []byte 7 | AddUser chan []byte //广播用户进入或退出 8 | } 9 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code02/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

Hello Go

10 |

{{.Msg}}

11 | 12 | 13 | -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/bin/Debug/ChatClient.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter12/ChatClient/ChatClient/bin/Debug/ChatClient.exe -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/bin/Debug/ChatClient.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter12/ChatClient/ChatClient/bin/Debug/ChatClient.pdb -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/ChatClient.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/ChatClient.exe -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/ChatClient.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/ChatClient.pdb -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/less/screen-reader.less: -------------------------------------------------------------------------------- 1 | // Screen Readers 2 | // ------------------------- 3 | 4 | .sr-only { .sr-only(); } 5 | .sr-only-focusable { .sr-only-focusable(); } 6 | -------------------------------------------------------------------------------- /go.introduce/chapter12/chat/server/broadcast.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | func broadcast(userName string) { 4 | for _, v := range onlineUsers { 5 | v.AddUser <- []byte("用户[" + userName + "]已加入聊天室\n") 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code05/app/app.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "go.introduce/chapter02/code05/app/config" 5 | ) 6 | 7 | //GetVer 获取版本信息 8 | func GetVer() string { 9 | return config.Cver 10 | } 11 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/less/fixed-width.less: -------------------------------------------------------------------------------- 1 | // Fixed Width Icons 2 | // ------------------------- 3 | .@{fa-css-prefix}-fw { 4 | width: (18em / 14); 5 | text-align: center; 6 | } 7 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/scss/_fixed-width.scss: -------------------------------------------------------------------------------- 1 | // Fixed Width Icons 2 | // ------------------------- 3 | .#{$fa-css-prefix}-fw { 4 | width: (18em / 14); 5 | text-align: center; 6 | } 7 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter11/code06/server/font/font-awesome/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /go.introduce/chapter02/code05/code05.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "go.introduce/chapter02/code05/app" 7 | ) 8 | 9 | func main() { 10 | fmt.Println("app.GetVer() is " + app.GetVer()) 11 | } 12 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/scss/_screen-reader.scss: -------------------------------------------------------------------------------- 1 | // Screen Readers 2 | // ------------------------- 3 | 4 | .sr-only { @include sr-only(); } 5 | .sr-only-focusable { @include sr-only-focusable(); } 6 | -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/.vs/ChatClient/v15/Server/sqlite3/storage.ide: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter12/ChatClient/.vs/ChatClient/v15/Server/sqlite3/storage.ide -------------------------------------------------------------------------------- /go.introduce/chapter02/code06/app/a.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "fmt" 5 | 6 | _ "go.introduce/chapter02/code06/app/config" 7 | ) 8 | 9 | func init() { 10 | 11 | fmt.Println("app package a.go init()") 12 | } 13 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code07/bool.go: -------------------------------------------------------------------------------- 1 | //布尔示例 2 | package main 3 | 4 | import "fmt" 5 | 6 | func main() { 7 | var a = true 8 | //a = 1 9 | var b bool 10 | fmt.Printf("a=%t\n", a) 11 | fmt.Printf("b=%t\n", b) 12 | } 13 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code07/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | ch := make(chan int) 9 | go func() { 10 | ch <- 7 11 | }() 12 | ch <- 8 13 | fmt.Println(<-ch) 14 | } 15 | -------------------------------------------------------------------------------- /go.introduce/chapter10/code10/ydorm/field.go: -------------------------------------------------------------------------------- 1 | package ydorm 2 | 3 | import "reflect" 4 | 5 | //FieldInfo 表字段信息 6 | type FieldInfo struct { 7 | Name string 8 | IsPrimaryKey bool 9 | refValue reflect.Value 10 | } 11 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter11/code06/server/font/font-awesome/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter11/code06/server/font/font-awesome/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter11/code06/server/font/font-awesome/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/ChatClient.FrmChat.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/ChatClient.FrmChat.resources -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter11/code06/server/font/font-awesome/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /go.introduce/chapter02/code02/code02.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "go.introduce/chapter02/code01" 7 | ) 8 | 9 | func main() { 10 | //调用code01包中的Hello函数 11 | code01.Hello() 12 | fmt.Println("==========") 13 | } 14 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code04/code04.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | demo "go.introduce/chapter02/code03" 7 | ) 8 | 9 | func main() { 10 | //调用demo包中的Hello函数 11 | demo.Hello() 12 | fmt.Println("==========") 13 | } 14 | -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/ChatClient.csproj.GenerateResource.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/ChatClient.csproj.GenerateResource.cache -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/ChatClient.csprojAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/ChatClient.csprojAssemblyReference.cache -------------------------------------------------------------------------------- /go.introduce/chapter12/mysql.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `go_chat`.`chat_logs` ( 2 | `id` BIGINT NOT NULL auto_increment, 3 | `message` VARCHAR(1000) NULL, 4 | `addtime` DATETIME DEFAULT CURRENT_TIMESTAMP , 5 | `address` VARCHAR(50) NULL, 6 | PRIMARY KEY (`id`)); -------------------------------------------------------------------------------- /go.introduce/chapter02/code07/opt_note.go: -------------------------------------------------------------------------------- 1 | //注释示例 2 | package main 3 | 4 | import "fmt" 5 | 6 | func main() { 7 | //声明字符串类型的变量a 8 | a := "Hello" 9 | /* 10 | 对变量a进行重新赋值 11 | */ 12 | a = "World" 13 | //打印字符串a 14 | fmt.Printf("%s \n", a) 15 | } 16 | -------------------------------------------------------------------------------- /go.introduce/chapter06/code06/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var a int32 = 7 7 | p := &a 8 | pp := &p 9 | **pp = 9 10 | fmt.Println(a) //9 11 | fmt.Println(*&a) //9 12 | fmt.Println(*&*&a) //9 13 | } 14 | -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/ChatClient.Properties.Resources.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/ChatClient.Properties.Resources.resources -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/DesignTimeResolveAssemblyReferences.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/DesignTimeResolveAssemblyReferences.cache -------------------------------------------------------------------------------- /go.introduce/chapter09/code04/main2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | func main() { 9 | //go 匿名函数 10 | go func(msg string) { 11 | fmt.Println(msg) 12 | }("Hello Goroutine") 13 | time.Sleep(1 * time.Second) 14 | } 15 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code03/entity/bmw.go: -------------------------------------------------------------------------------- 1 | package entity 2 | 3 | import "fmt" 4 | 5 | //BMW 结构体实现了Drive方法 6 | type BMW struct { 7 | } 8 | 9 | //Drive 实现了IDrive接口方法 10 | func (*BMW) Drive(name string) { 11 | fmt.Println("Drive BMW " + name + " Car") 12 | } 13 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code02/onecore/coffeemachine.go: -------------------------------------------------------------------------------- 1 | package onecore 2 | 3 | import "sync" 4 | 5 | //CoffeeMachine 咖啡机(共享1个) 6 | type CoffeeMachine struct { 7 | CoffeeName string 8 | Gopher //获取使用权的地鼠 9 | Mlock sync.Mutex //互斥锁 10 | } 11 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |

sorry,happen error

11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/bin/Debug/ChatClient.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/ChatClient.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/ChatClient.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/Go_Concurrency_Programming/master/go.introduce/chapter12/ChatClient/ChatClient/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /go.introduce/chapter02/code07/var2.go: -------------------------------------------------------------------------------- 1 | //变量函数体外声明示例 2 | package main 3 | 4 | import "fmt" 5 | 6 | var a int 7 | 8 | //函数体外只能声明变量,而不能对变量进行赋值 9 | //a = 2 10 | func main() { 11 | //局部变量 12 | var a int = 1 13 | //类型int,值1 14 | fmt.Printf("类型%T,值%d \n", a, a) 15 | } 16 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code23/ydbase/config.go: -------------------------------------------------------------------------------- 1 | package ydbase 2 | 3 | var config struct { 4 | uname string 5 | pwd string 6 | isLogin bool 7 | } 8 | 9 | func init() { 10 | config.uname = "root" 11 | config.pwd = "123" 12 | config.isLogin = false 13 | } 14 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code03/entity/aodi.go: -------------------------------------------------------------------------------- 1 | package entity 2 | 3 | import "fmt" 4 | 5 | //AoDi 结构体实现了Drive方法 6 | type AoDi struct { 7 | } 8 | 9 | //Drive 实现了IDrive接口方法 10 | func (AoDi) Drive(name string) { 11 | fmt.Println("Drive AoDi " + name + " Car") 12 | } 13 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code07/sql/dbdata.go: -------------------------------------------------------------------------------- 1 | package sql 2 | 3 | //DbData 构建SQL语句的对象 4 | type DbData struct { 5 | Table string 6 | Fields string 7 | Where []WhereItem 8 | OrderBy []OrderByItem 9 | PageIndex int 10 | PageSize int 11 | DbType 12 | } 13 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code06/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | _ "go.introduce/chapter02/code06/app" 7 | ) 8 | 9 | func init() { 10 | fmt.Println("main package init()") 11 | } 12 | func main() { 13 | 14 | fmt.Println("main package main()") 15 | } 16 | -------------------------------------------------------------------------------- /go.introduce/chapter03/code05/func.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | //匿名函数只能调用一次 7 | s, m := func(a int, b int) (int, int) { 8 | return a + b, a * b 9 | }(2, 3) 10 | //匿名函数(2, 3)=5,6 11 | fmt.Printf("匿名函数(2, 3)=%d,%d \n", s, m) 12 | 13 | } 14 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code03/parallel/coffeemachine.go: -------------------------------------------------------------------------------- 1 | package parallel 2 | 3 | import "sync" 4 | 5 | //CoffeeMachine 咖啡机 6 | type CoffeeMachine struct { 7 | Name string 8 | CoffeeName string 9 | Gopher //获取使用权的地鼠 10 | Mlock sync.Mutex //互斥锁 11 | } 12 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code04/main3.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | func main() { 9 | //匿名函数赋值给变量 10 | printHello := func(msg string) { 11 | fmt.Println(msg) 12 | } 13 | go printHello("Hello Goroutine") 14 | time.Sleep(1 * time.Second) 15 | } 16 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code06/app/config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import "fmt" 4 | 5 | var Name = "" 6 | 7 | func init() { 8 | fmt.Println("config package init() B ") 9 | Name = "B" 10 | } 11 | 12 | func init() { 13 | fmt.Println("config package init() A") 14 | Name = "A" 15 | } 16 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/web/resdata.go: -------------------------------------------------------------------------------- 1 | package web 2 | 3 | //ResData 返回数据格式 4 | //属性必须大写,否则JSON序列化忽略 5 | type ResData struct { 6 | Code int `json:"code"` 7 | Msg string `json:"msg"` 8 | Data string `json:"data"` 9 | Tag []interface{} `json:"tag"` 10 | } 11 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code23/ydbase/login.go: -------------------------------------------------------------------------------- 1 | package ydbase 2 | 3 | //Login 用户和密码登录 4 | func Login(uname, pwd string) bool { 5 | if uname == config.uname && pwd == config.pwd { 6 | config.isLogin = true 7 | 8 | } else { 9 | config.isLogin = false 10 | } 11 | 12 | return config.isLogin 13 | } 14 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code06/entity/factory.go: -------------------------------------------------------------------------------- 1 | package entity 2 | 3 | func Factory(name string) IDuck { 4 | switch name { 5 | case "duck": 6 | return &Duck{Color: "White", Age: 3} 7 | case "goose": 8 | return &Goose{Color: "Black"} 9 | default: 10 | panic("No such animal") 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code04/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | func main() { 9 | //go+空格+函数或者方法调用,即可创建goroutine 10 | go printHello("Hello Goroutine") 11 | time.Sleep(1 * time.Second) 12 | } 13 | func printHello(msg string) { 14 | fmt.Println(msg) 15 | } 16 | -------------------------------------------------------------------------------- /go.introduce/chapter10/code10/entity/student.go: -------------------------------------------------------------------------------- 1 | package entity 2 | 3 | //Student 用Tag进行字段信息描述 4 | type Student struct { 5 | TableName string "t_student" 6 | Id string `field:"id" iskey:"1"` 7 | Name string `field:"cname"` 8 | Age int `field:"age"` 9 | Sex string 10 | } 11 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code07/main4.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | ) 7 | 8 | func main() { 9 | var wg sync.WaitGroup 10 | for i := 0; i < 20; i++ { 11 | wg.Add(1) 12 | go func() { 13 | fmt.Println(i) //数据竞争 14 | wg.Done() 15 | }() 16 | } 17 | wg.Wait() 18 | } 19 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code02/entity/person.go: -------------------------------------------------------------------------------- 1 | package entity 2 | 3 | import "fmt" 4 | 5 | type Person struct { 6 | name string 7 | age int 8 | sex string 9 | } 10 | 11 | func (p *Person) Walk() { 12 | fmt.Println("Person walk") 13 | } 14 | func (p *Person) Eat() { 15 | fmt.Println("Person Eat") 16 | } 17 | -------------------------------------------------------------------------------- /go.introduce/chapter03/code08/func.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | //递归函数实现斐波那契数列 8 | func fib(n int64) int64 { 9 | if n < 2 { 10 | return n 11 | } 12 | return fib(n-2) + fib(n-1) 13 | } 14 | 15 | func main() { 16 | var i int64 = 8 17 | fmt.Printf("fib(8)= %d\n", fib(i)) //21 18 | } 19 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code05/main3.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | ch := make(chan int) 9 | go func() { 10 | ch <- 7 11 | }() 12 | fmt.Println(<-ch) //阻塞直到读取到值7 13 | //fmt.Println(<-ch) //读取超时,deadlock 14 | var input string 15 | fmt.Scanln(&input) 16 | 17 | } 18 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/css/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 0; 3 | font-size: 16px; 4 | font-family: 'Courier New', Courier, monospace; 5 | } 6 | 7 | .avatar { 8 | border: solid 1px #eee; 9 | border-radius: 30px; 10 | width: 60px; 11 | height: 60px; 12 | overflow: hidden; 13 | } -------------------------------------------------------------------------------- /go.introduce/chapter09/code05/main6.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | ch := make(chan int) 9 | go func() { 10 | for i := 0; i < 10; i++ { 11 | ch <- i 12 | } 13 | close(ch) 14 | }() 15 | //for range遍历通道 16 | for n := range ch { 17 | fmt.Println(n) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /go.introduce/chapter03/code01/func01.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func sum(a int, b int) int { 6 | return a + b 7 | } 8 | func main() { 9 | c := sum(2, 3) 10 | //sum(2, 3)=5 11 | fmt.Printf("sum(2, 3)=%d \n", c) 12 | } 13 | 14 | //逃逸分析 go build -gcflags "-l -m" .\func01.go 15 | //println("sum(2, 3)= ", c) 16 | -------------------------------------------------------------------------------- /go.introduce/chapter03/code02/func02.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func sum(a int, b int) func(int, int) int { 6 | return func(c int, d int) int { 7 | return a + b + c + d 8 | } 9 | } 10 | 11 | func main() { 12 | c := sum(2, 3)(4, 5) 13 | //sum(2, 3)=14 14 | fmt.Printf("sum(2, 3)(4, 5)=%d \n", c) 15 | } 16 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code23/ydbase/table.go: -------------------------------------------------------------------------------- 1 | package ydbase 2 | 3 | //Student 学生结构 4 | type Student struct { 5 | XH, Name string 6 | Age int 7 | Height float32 8 | } 9 | 10 | //学生表 11 | var studentTable = []Student{} 12 | 13 | func init() { 14 | //初始化表,容量100 15 | studentTable = make([]Student, 0, 100) 16 | } 17 | -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /go.introduce/chapter03/code11/func2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | //c int相当于定义了函数sum的局部变量c 8 | func sum(a, b int) (c int) { 9 | c = a + b 10 | d := 2 11 | fmt.Println(d) 12 | return //c=a+b 13 | //return d //2 14 | } 15 | func main() { 16 | //sum(2,3)= 5 17 | fmt.Println("sum(2,3)=", sum(2, 3)) 18 | } 19 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code08/usage.txt: -------------------------------------------------------------------------------- 1 | 2 | //go test -bench="." 3 | //go test -bench="." -race 4 | //go test -bench="." -cpuprofile cpu.out 5 | //go tool pprof -svg cpu.out > cpu.svg 6 | //go test -bench="." -memprofile mem.out 7 | //go tool pprof -svg mem.out > mem.svg 8 | //Is Graphviz installed? 9 | //exec: "dot": executable file not found in %PATH% -------------------------------------------------------------------------------- /go.introduce/chapter12/chat/server/connWrite.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "net" 5 | ) 6 | 7 | func connWrite(conn net.Conn, user userInfo) { 8 | 9 | for { 10 | select { 11 | case msg1 := <-user.AddUser: 12 | _, _ = conn.Write(msg1) 13 | case msg2 := <-user.perC: 14 | _, _ = conn.Write(msg2) 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /go.introduce/chapter06/code03/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | slice := []int{3, 4, 5, 6, 7} 9 | 10 | for _, value := range slice { 11 | value = 10 12 | //10 13 | fmt.Println(value) 14 | //所有迭代的value的地址是一样的 15 | fmt.Println(&value) 16 | } 17 | fmt.Println(slice) //[3 4 5 6 7] 18 | } 19 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code05/main2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | //用通道实现2个goroutine间通信 9 | ch := make(chan int) //通道 chan int类型 10 | ch <- 7 11 | //fatal error: all goroutines are asleep - deadlock! 12 | n := <-ch 13 | fmt.Println(n) 14 | var input string 15 | fmt.Scanln(&input) 16 | 17 | } 18 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code05/main4.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | ch := make(chan int) 9 | go func() { 10 | ch <- 7 11 | close(ch) //关闭后,其他goroutine可继续从ch中读取 12 | }() 13 | fmt.Println(<-ch) //阻塞直到读取到值7 14 | fmt.Println(<-ch) //可读取到值0 15 | var input string 16 | fmt.Scanln(&input) 17 | } 18 | -------------------------------------------------------------------------------- /go.introduce/chapter12/chat/server/init.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import "github.com/fatih/color" 4 | 5 | //全局channel,处理从各个客户端读到的消息 6 | var message = make(chan []byte) 7 | 8 | //用于存储在线用户信息 9 | var onlineUsers = make(map[string]userInfo) 10 | var ccS = color.New(color.FgGreen, color.Bold) //绿色 11 | var ccF = color.New(color.FgRed, color.Bold) //红色 12 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code10/mapreduce/mapworker.go: -------------------------------------------------------------------------------- 1 | package mapreduce 2 | 3 | //MapWorker 统计单词的个数,并给ReduceWorker准备数据 4 | func MapWorker(in <-chan string, out chan<- map[string]int) { 5 | count := map[string]int{} 6 | for word := range in { 7 | if word != "" { 8 | count[word] = count[word] + 1 9 | } 10 | } 11 | out <- count 12 | close(out) 13 | } 14 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code07/enum.go: -------------------------------------------------------------------------------- 1 | //常量枚举模拟示例 2 | package main 3 | 4 | import "fmt" 5 | 6 | //SEX 用int8定义了一个新的性别类型 7 | type SEX int8 8 | 9 | const ( 10 | //MAN SEX类型,值为1 11 | MAN SEX = 1 12 | //FEMALE SEX类型,值为0 13 | FEMALE SEX = 0 14 | ) 15 | 16 | func main() { 17 | const sex SEX = MAN 18 | //类型main.SEX,值1 19 | fmt.Printf("类型%T,值%v \n", sex, sex) 20 | } 21 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code06/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | //缓冲信道,容量为2 9 | ch := make(chan int, 2) 10 | ch <- 7 11 | ch <- 8 12 | ch <- 9 //超过容量2,继续写入则阻塞 13 | fmt.Println(len(ch)) //2 14 | fmt.Println(cap(ch)) //2 15 | n := <-ch 16 | fmt.Println(n) //7 17 | fmt.Println(<-ch) //8 18 | } 19 | -------------------------------------------------------------------------------- /go.introduce/chapter03/code06/func.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | //匿名函数赋值给变量f,可以多次调用 7 | f := func(a int, b int) (int, int) { 8 | return a + b, a * b 9 | } 10 | s, m := f(2, 3) 11 | //f(2, 3)=5,6 12 | fmt.Printf("f(2, 3)=%d,%d \n", s, m) 13 | s, m = f(3, 7) 14 | //f(2, 3)=10,21 15 | fmt.Printf("f(2, 3)=%d,%d \n", s, m) 16 | } 17 | -------------------------------------------------------------------------------- /go.introduce/chapter06/code04/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "unsafe" 6 | ) 7 | 8 | func main() { 9 | var a int32 = 8 10 | var f int64 = 20 11 | ptr := &a //*int32 12 | fmt.Println(ptr) 13 | ptr = (*int32)(unsafe.Pointer(&f)) //*int64 -> *int32 14 | fmt.Println(ptr) 15 | *ptr = 10 16 | fmt.Println(a) //8 17 | fmt.Println(f) //10 18 | } 19 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code03/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | ) 7 | 8 | func handler(w http.ResponseWriter, r *http.Request) { 9 | fmt.Fprintf(w, "Hello Go https") 10 | } 11 | 12 | //https://localhost 13 | func main() { 14 | http.HandleFunc("/", handler) 15 | http.ListenAndServeTLS(":443", "server.crt", "server.pem", nil) 16 | } 17 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "go.introduce/chapter07/code02/entity" 7 | ) 8 | 9 | func main() { 10 | stu := entity.Student{} 11 | stu.New("jack", 33, "男", "CUMT") 12 | //stu.name 13 | fmt.Println(stu) 14 | stu.GotoSchool() 15 | //覆盖了Person的Walk方法 16 | stu.Walk() 17 | //继承Person的Eat方法 18 | stu.Eat() 19 | } 20 | -------------------------------------------------------------------------------- /go.introduce/chapter08/code01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | ) 7 | 8 | func main() { 9 | //文件读取到内存中,一般为小文件 10 | content, err := ioutil.ReadFile("hello.txt") 11 | if err != nil { 12 | fmt.Println("文件读取失败:", err) 13 | return 14 | } else { 15 | //[]byte转string 16 | fmt.Println("文件内容为:", string(content)) 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code05/main5.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | ch := make(chan int) 9 | go func() { 10 | ch <- 0 11 | ch <- 7 12 | close(ch) 13 | }() 14 | for { 15 | if n, ok := <-ch; ok { 16 | fmt.Println(n) 17 | } else { 18 | break 19 | } 20 | } 21 | var input string 22 | fmt.Scanln(&input) 23 | } 24 | -------------------------------------------------------------------------------- /go.introduce/chapter03/code08/func2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | //fibNoRec 非递归实现斐波那契数列 6 | func fibNoRec(n int64) int64 { 7 | var f1 int64 = 0 8 | var f2 int64 = 1 9 | var i int64 = 0 10 | for ; i < n; i++ { 11 | f1, f2 = f2, f1+f2 12 | } 13 | return f1 14 | } 15 | func main() { 16 | fmt.Printf("fibNoRec(50)= %d\n", fibNoRec(50)) //12586269025 17 | } 18 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code10/mapreduce/reduceworker.go: -------------------------------------------------------------------------------- 1 | package mapreduce 2 | 3 | //ReduceCountWorker 汇总统计单词的个数 4 | func ReduceCountWorker(in <-chan map[string]int, out chan<- map[string]int) { 5 | count := map[string]int{} 6 | for n := range in { 7 | for word := range n { 8 | count[word] = count[word] + n[word] 9 | } 10 | } 11 | out <- count 12 | close(out) 13 | } 14 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code07/const.go: -------------------------------------------------------------------------------- 1 | //常量示例 2 | package main 3 | 4 | import "fmt" 5 | 6 | func main() { 7 | const ver string = "1.0.0" 8 | const author = "jackwang" 9 | //一行多个常量 10 | const a, b = 1, 2 11 | //常量用作枚举 12 | const ( 13 | A = "0" 14 | B = "1" 15 | ) 16 | //常量可以不使用 17 | fmt.Printf("类型%T,值%s \n", ver, ver) 18 | fmt.Printf("类型%T,值%s \n", author, author) 19 | } 20 | -------------------------------------------------------------------------------- /go.introduce/chapter08/code11/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | 7 | "go.introduce/chapter08/code11/property" 8 | ) 9 | 10 | func main() { 11 | //go run .\main.go -fkey db.uname 12 | content := flag.String("fkey", "db.uname", "-fkey指定配置文件的key") 13 | flag.Parse() 14 | 15 | fmt.Printf("key[%s]->%s", *content, property.Read(*content)) 16 | 17 | } 18 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/main.go: -------------------------------------------------------------------------------- 1 | // package main 2 | 3 | // import ( 4 | // "fmt" 5 | // "net/http" 6 | 7 | // "go.introduce/charpter11/code06/server/web" 8 | // ) 9 | 10 | // //go run main.go 则会路径不一致 11 | // func main() { 12 | // web.RegisterRouter() 13 | // err := http.ListenAndServe(":8080", nil) 14 | // if err != nil { 15 | // fmt.Println(err) 16 | // } 17 | // } 18 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code08/counter_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func BenchmarkCounter(b *testing.B) { 8 | b.ReportAllocs() //报告内存分配信息 9 | // b.N 循环次数 10 | for i := 0; i < b.N; i++ { 11 | Counter() 12 | } 13 | } 14 | func BenchmarkCounter2(b *testing.B) { 15 | b.ReportAllocs() 16 | for i := 0; i < b.N; i++ { 17 | Counter2() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code07/main2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | ) 7 | 8 | func main() { 9 | var counter = 0 10 | var wg sync.WaitGroup 11 | //20并发量小,不容易出现问题 12 | //当并发量大时(如20000)可能就会出现问题 13 | for i := 0; i < 20; i++ { 14 | wg.Add(1) 15 | go func() { 16 | counter++ 17 | wg.Done() 18 | }() 19 | } 20 | wg.Wait() 21 | fmt.Println(counter) 22 | } 23 | -------------------------------------------------------------------------------- /go.introduce/chapter06/code09/linklist/linklist_find.go: -------------------------------------------------------------------------------- 1 | package linklist 2 | 3 | import "errors" 4 | 5 | func (this *LinkList) Find(index uint) (*ListNode, error) { 6 | if index < 0 || index >= this.length { 7 | return nil, errors.New("越界") 8 | } 9 | 10 | cur := this.head.GetNext() 11 | for i := uint(0); i < index; i++ { 12 | cur = cur.GetNext() 13 | } 14 | 15 | return cur, nil 16 | } 17 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code05/sse/sse.go: -------------------------------------------------------------------------------- 1 | package sse 2 | 3 | //NewSSE 实例化Broker并启动监听 4 | func NewSSE() (broker *Broker) { 5 | broker = &Broker{ 6 | Notifier: make(chan []byte, 1), 7 | newClients: make(chan chan []byte), 8 | closingClients: make(chan chan []byte), 9 | clients: make(map[chan []byte]bool), 10 | } 11 | //开启监听 12 | go broker.listen() 13 | 14 | return 15 | } 16 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code06/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "go.introduce/chapter07/code06/entity" 7 | ) 8 | 9 | func main() { 10 | animal := entity.Factory("duck") 11 | animal.SingGua() 12 | fmt.Printf("animal is %s ", animal.Type()) 13 | animal = entity.Factory("goose") 14 | fmt.Println() 15 | animal.SingGua() 16 | fmt.Printf("animal is %s ", animal.Type()) 17 | } 18 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/HELP-US-OUT.txt: -------------------------------------------------------------------------------- 1 | I hope you love Font Awesome. If you've found it useful, please do me a favor and check out my latest project, 2 | Fort Awesome (https://fortawesome.com). It makes it easy to put the perfect icons on your website. Choose from our awesome, 3 | comprehensive icon sets or copy and paste your own. 4 | 5 | Please. Check it out. 6 | 7 | -Dave Gandy 8 | -------------------------------------------------------------------------------- /go.introduce/chapter06/code07/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | //指针声明未初始化,野指针 9 | var ptr *int 10 | //打印指针ptr指向的地址 11 | fmt.Printf("%p\n", ptr) // 0x0 12 | //panic: 无效的内存地址或nil指针解引用(pointer dereference) 13 | //*ptr = 3 //野指针不能进行*ptr取值 14 | fmt.Println(ptr) // 15 | var a int = 7 16 | //可以重新指向 17 | ptr = &a 18 | *ptr = 3 19 | fmt.Println(a) //3 20 | } 21 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | 7 | "go.introduce/chapter11/code06/server/web" 8 | ) 9 | 10 | //http://localhost:8080/index.gohtml 11 | func main() { 12 | web.RegisterRouter() 13 | fmt.Println("start Go Web Server at port 8080") 14 | err := http.ListenAndServe(":8080", nil) 15 | if err != nil { 16 | fmt.Println(err) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "go.introduce/chapter07/code01/entity" 7 | ) 8 | 9 | func main() { 10 | 11 | p := entity.Person{} 12 | //私有属性和方法不能访问 13 | //p.name = "Jack" 14 | //p.walk() 15 | p.SetName("Jack") 16 | p.SetAge(33) 17 | p.SetSex("男") 18 | p.Eat() //Person Eat 19 | fmt.Printf("%+v", p) //{name:Jack age:33 sex:男} 20 | 21 | } 22 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code07/main3.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | "sync/atomic" 7 | ) 8 | 9 | //go run -race main3.go 10 | func main() { 11 | var counter int32 = 0 12 | var wg sync.WaitGroup 13 | for i := 0; i < 20; i++ { 14 | wg.Add(1) 15 | go func() { 16 | atomic.AddInt32(&counter, 1) //原子操作 17 | wg.Done() 18 | }() 19 | } 20 | wg.Wait() 21 | fmt.Println(counter) 22 | } 23 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code06/main4.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | "time" 7 | ) 8 | 9 | func main() { 10 | go showRecord() 11 | time.Sleep(time.Second) 12 | buf := make([]byte, 10000) 13 | runtime.Stack(buf, true) 14 | fmt.Println(string(buf)) 15 | } 16 | 17 | func showRecord() { 18 | tiker := time.Tick(time.Second) 19 | for t := range tiker { 20 | fmt.Println(t) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | //定义一个新的类型name 8 | type name string 9 | 10 | func main() { 11 | var myname name = "Jack" 12 | myname2 := myname 13 | //main.name 14 | fmt.Printf("%T \n", myname2) 15 | fmt.Printf("%t \n", myname2 == "Jack") //true 16 | //myname3 := "Jack" 17 | //类型name和string不匹配,无法比较 18 | //fmt.Printf("%t \n", myname2 == myname3) //错误 19 | } 20 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code18/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func sum(slice []int) int { 8 | length := len(slice) 9 | ret := 0 10 | for i := 0; i < length; i++ { 11 | ret += slice[i] 12 | } 13 | return ret 14 | } 15 | func main() { 16 | var slice []int 17 | for i := 1; i <= 10; i++ { 18 | slice = append(slice, i) 19 | } 20 | ret := sum(slice) 21 | //55 22 | fmt.Println(ret) 23 | } 24 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code11/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func change(arr [10]int) { 8 | length := len(arr) 9 | for i := 0; i < length; i++ { 10 | arr[i] = 2 * i 11 | } 12 | 13 | } 14 | func main() { 15 | 16 | var arr [10]int 17 | length := len(arr) 18 | for i := 1; i <= length; i++ { 19 | arr[i-1] = i 20 | } 21 | change(arr) 22 | //[1 2 3 4 5 6 7 8 9 10] 23 | fmt.Println(arr) 24 | } 25 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code10/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | "go.introduce/chapter09/code10/mapreduce" 8 | ) 9 | 10 | func main() { 11 | //go run .\main.go -race 12 | t := time.Now() 13 | input := "Go is awesome,Go is Best,Best are Good!\nYou are Hero,Thank You." 14 | 15 | fmt.Println(mapreduce.Run(input)) 16 | elapsed := time.Since(t) 17 | fmt.Println("time elapsed:", elapsed) 18 | } 19 | -------------------------------------------------------------------------------- /go.introduce/chapter03/code10/func.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | //闭包实现的累加器adder函数 8 | func adder(i int) func(int) int { 9 | ret := i 10 | return func(n int) int { 11 | ret += n 12 | return ret 13 | } 14 | } 15 | func main() { 16 | fc := adder(2) 17 | // 2 + 1+2+3 -> 8 18 | fc(1) 19 | fc(2) 20 | fc(3) 21 | //13 = 8 + 5 22 | fmt.Println(fc(5)) 23 | //20 = 13 + 7 24 | fmt.Println(fc(7)) 25 | } 26 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code17/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func change(slice []int) { 8 | slice[1] = 99 9 | } 10 | func main() { 11 | 12 | slice := []int{1, 2, 3, 4, 5} 13 | slice2 := []int{6, 7, 8, 9, 10} 14 | //合并 15 | slice = append(slice, slice2...) 16 | //[1 2 3 4 5 6 7 8 9 10] 17 | fmt.Println(slice) 18 | change(slice) 19 | //[1 99 3 4 5 6 7 8 9 10] 20 | fmt.Println(slice) 21 | 22 | } 23 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code04/main4.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | ) 7 | 8 | func main() { 9 | runtime.GOMAXPROCS(4) 10 | var counter = 0 11 | 12 | func() { 13 | for i := 0; i < 1000; i++ { 14 | go func() { 15 | counter++ 16 | }() 17 | } 18 | }() 19 | fmt.Println("执行完成,按任意键退出") 20 | var input string 21 | fmt.Scanln(&input) //阻塞等待用户输入 22 | fmt.Println(counter) //一般不是1000,每次不同 23 | } 24 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code07/opt_other.go: -------------------------------------------------------------------------------- 1 | //特殊运算符示例 2 | package main 3 | 4 | import "fmt" 5 | 6 | func main() { 7 | a, b := 2, "Hello" 8 | //&返回变量存储地址 9 | var p = &a 10 | var p1 = &b 11 | fmt.Printf("&a = %x \n", p) //&a = c000012090 12 | fmt.Printf("&b = %x \n", p1) //&b = c0000361f0 13 | //*返回变量存储地址的值 14 | c := *p 15 | c2 := *p1 16 | fmt.Printf("*p = %d \n", c) //*p = 2 17 | fmt.Printf("*p1 = %s \n", c2) //*p1 = Hello 18 | } 19 | -------------------------------------------------------------------------------- /go.introduce/chapter06/code09/linklist/listnode.go: -------------------------------------------------------------------------------- 1 | //Go单链表实现 2 | package linklist 3 | 4 | type ListNode struct { 5 | data int 6 | next *ListNode 7 | } 8 | 9 | func CreateLinkNode(value int) *ListNode { 10 | return &ListNode{ 11 | data: value, 12 | next: nil, 13 | } 14 | } 15 | 16 | func (this *ListNode) GetNext() *ListNode { 17 | return this.next 18 | } 19 | 20 | func (this *ListNode) GetValue() int { 21 | return this.data 22 | } 23 | -------------------------------------------------------------------------------- /go.introduce/chapter03/code07/func.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | //... 表示一个变长函数参数 6 | func sum(ns ...int) int { 7 | ret := 0 8 | for _, n := range ns { 9 | ret += n 10 | } 11 | return ret 12 | } 13 | 14 | func main() { 15 | fmt.Println(sum()) // 0 16 | fmt.Println(sum(1)) // 1 17 | fmt.Println(sum(2, 3)) // 5 18 | fmt.Println(sum(2, 3, 4)) // 9 19 | // nums := []int{1, 2, 3, 4} 20 | // sum(nums...) 21 | } 22 | -------------------------------------------------------------------------------- /go.introduce/chapter04/code01/main.go: -------------------------------------------------------------------------------- 1 | //if判断示例 2 | package main 3 | 4 | import ( 5 | "fmt" 6 | ) 7 | 8 | //审批流程 9 | func approve(days int) string { 10 | if days > 3 { 11 | return "总经理审批" 12 | } else { //else不能换行 13 | return "HR审批" 14 | } 15 | } 16 | func main() { 17 | days := 3 18 | ret := approve(days) 19 | fmt.Printf("请假%d天,需要%s\n", days, ret) 20 | days = 5 21 | ret = approve(days) 22 | fmt.Printf("请假%d天,需要%s\n", days, ret) 23 | } 24 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code06/entity/duck.go: -------------------------------------------------------------------------------- 1 | package entity 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type Duck struct { 8 | Color string 9 | Age int 10 | } 11 | 12 | func (this *Duck) Sleep() { 13 | fmt.Println("Duck Sleep") 14 | } 15 | func (this *Duck) Eat() { 16 | fmt.Println("Duck Eat") 17 | } 18 | func (this *Duck) SingGua() { 19 | fmt.Println("Duck SingGua") 20 | } 21 | func (this *Duck) Type() string { 22 | return "Duck" 23 | } 24 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code06/entity/goose.go: -------------------------------------------------------------------------------- 1 | package entity 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type Goose struct { 8 | Color string 9 | } 10 | 11 | func (this *Goose) Sleep() { 12 | fmt.Println("Goose Sleep") 13 | } 14 | func (this *Goose) Eat() { 15 | fmt.Println("Goose Eat") 16 | } 17 | func (this *Goose) SingGua() { 18 | fmt.Println("Goose SingGua") 19 | } 20 | func (this *Goose) Type() string { 21 | return "Goose,Like Duck" 22 | } 23 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type mystr = string 8 | 9 | func main() { 10 | var myname mystr = "Jack" 11 | myname = "Smith" 12 | //类型仍然是string 13 | fmt.Printf("%T \n", myname) 14 | myname2 := "Smith" 15 | fmt.Printf("%t \n", myname2 == myname) //true 16 | //Go内置的两个类型别名 17 | var a byte 18 | fmt.Printf("%T \n", a) //uint8 19 | var c rune 20 | fmt.Printf("%T \n", c) //int32 21 | } 22 | -------------------------------------------------------------------------------- /go.introduce/chapter03/code03/func03.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | //sumAndmul 返回两个值,一个是和,一个是乘 6 | func sumAndmul(a int, b int) (int, int) { 7 | return a + b, a * b 8 | } 9 | func main() { 10 | s, m := sumAndmul(2, 3) 11 | //sumAndmul(2, 3)=5,6 12 | fmt.Printf("sumAndmul(2, 3)=%d,%d \n", s, m) 13 | s1, _ := sumAndmul(2, 3) 14 | //sumAndmul(2, 3)->5 15 | fmt.Printf("sumAndmul(2, 3)->%d\n", s1) 16 | //可以不赋值 17 | sumAndmul(2, 3) 18 | } 19 | -------------------------------------------------------------------------------- /go.introduce/chapter03/code12/main.go: -------------------------------------------------------------------------------- 1 | //原子计算器2.0迭代版 2 | //基于函数实现基本计算功能 3 | package main 4 | 5 | import ( 6 | "fmt" 7 | 8 | "go.introduce/chapter03/code12/calc" 9 | ) 10 | 11 | func main() { 12 | //质子,中子,电子 13 | p, n, e := 0, 0, 0 14 | //Scanln遇到换行时才停止扫描 15 | fmt.Scanln(&p, &n, &e) 16 | //函数多返回值 17 | Z, A, c := calc.AtomCalc(p, n, e) 18 | fmt.Printf("当质子p=%d、中子n=%d和电子e=%d时 \n", p, n, e) 19 | fmt.Printf("原子序数Z=%d、原子质量A=%d和电荷c=%d \n", Z, A, c) 20 | } 21 | -------------------------------------------------------------------------------- /go.introduce/chapter04/code08/main.go: -------------------------------------------------------------------------------- 1 | //break和continue语句示例 2 | package main 3 | 4 | import "fmt" 5 | 6 | func main() { 7 | m := 10 8 | for { 9 | if m == 8 { 10 | break 11 | } 12 | fmt.Printf("%d\n", m) 13 | m-- 14 | } 15 | fmt.Println("=======") 16 | fmt.Println("m=", m) 17 | for { 18 | m-- 19 | if m == 7 || m == 5 { 20 | continue 21 | } 22 | if m <= 3 { 23 | break 24 | } 25 | fmt.Printf("%d\n", m) 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code07/opt_logic.go: -------------------------------------------------------------------------------- 1 | //逻辑运算符示例 2 | package main 3 | 4 | import "fmt" 5 | 6 | func main() { 7 | a, b := 11, 2 8 | isOk := false 9 | //&&逻辑与运算符 10 | //如果两边的操作数都是 true,则条件 true,否则为 false 11 | fmt.Printf("%t \n", a > b && isOk) //false 12 | //||逻辑或运算符 13 | //如果两边的操作数有一个 true,则条件 true,否则为 false 14 | fmt.Printf("%t \n", a > b || isOk) //true 15 | //!逻辑非运算符 16 | //如果条件为 true,则逻辑非条件 false,否则为 true 17 | fmt.Printf("%t \n", !isOk) //true 18 | } 19 | -------------------------------------------------------------------------------- /go.introduce/chapter03/code11/func.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func print(s string) { 8 | fmt.Println("run ", s) 9 | } 10 | func main() { 11 | fmt.Println("====start=====") 12 | //defer执行顺序和调用顺序相反 13 | defer print("order 1") 14 | defer print("order 2") 15 | defer print("order 3") 16 | fmt.Println("====end=====") 17 | } 18 | 19 | // ====start===== 20 | // ====end===== 21 | // run order 3 22 | // run order 2 23 | // run order 1 24 | -------------------------------------------------------------------------------- /go.introduce/chapter08/code10/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path/filepath" 7 | ) 8 | 9 | //遍历目录和文件 10 | func visit(path string, f os.FileInfo, err error) error { 11 | fmt.Printf("%s\n", path) 12 | return nil 13 | } 14 | 15 | func main() { 16 | //遍历当前目录 17 | if root, err := os.Getwd(); err == nil { 18 | err := filepath.Walk(root, visit) 19 | if err != nil { 20 | fmt.Printf("%v\n", err) 21 | } 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /go.introduce/chapter04/code03/main.go: -------------------------------------------------------------------------------- 1 | //swith示例 2 | package main 3 | 4 | import ( 5 | "fmt" 6 | ) 7 | 8 | //swith获取性别 9 | func getSex(code int) string { 10 | switch code { 11 | case 1: 12 | return "男" 13 | case 0: 14 | return "女" 15 | default: 16 | return "未知" 17 | } 18 | } 19 | func main() { 20 | code := 1 21 | ret := getSex(code) 22 | fmt.Printf("%d->%s\n", code, ret) 23 | code = 0 24 | ret = getSex(code) 25 | fmt.Printf("%d->%s\n", code, ret) 26 | } 27 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code07/sql/dbtype.go: -------------------------------------------------------------------------------- 1 | package sql 2 | 3 | //DbType 数据库类型枚举 4 | type DbType int32 5 | 6 | const ( 7 | MYSQL DbType = 1 8 | MSSQL DbType = 2 9 | ) 10 | 11 | var DbMapLeft map[DbType]string 12 | var DbMapRight map[DbType]string 13 | 14 | func init() { 15 | DbMapLeft = make(map[DbType]string) 16 | DbMapLeft[MYSQL] = "`" 17 | DbMapLeft[MSSQL] = "[" 18 | DbMapRight = make(map[DbType]string) 19 | DbMapRight[MYSQL] = "`" 20 | DbMapRight[MSSQL] = "]" 21 | } 22 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code04/main5.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | ) 7 | 8 | var wg sync.WaitGroup 9 | 10 | func div(num int) { 11 | defer func() { 12 | err := recover() 13 | if err != nil { 14 | fmt.Println(err) 15 | } 16 | wg.Done() //放于此,保证执行 17 | }() 18 | fmt.Printf("10/%d=%d\n", num, 10/num) 19 | } 20 | func main() { 21 | for i := 0; i < 10; i++ { 22 | wg.Add(1) 23 | go div(i) 24 | } 25 | wg.Wait() //等待所有goroutine执行完成 26 | } 27 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/less/larger.less: -------------------------------------------------------------------------------- 1 | // Icon Sizes 2 | // ------------------------- 3 | 4 | /* makes the font 33% larger relative to the icon container */ 5 | .@{fa-css-prefix}-lg { 6 | font-size: (4em / 3); 7 | line-height: (3em / 4); 8 | vertical-align: -15%; 9 | } 10 | .@{fa-css-prefix}-2x { font-size: 2em; } 11 | .@{fa-css-prefix}-3x { font-size: 3em; } 12 | .@{fa-css-prefix}-4x { font-size: 4em; } 13 | .@{fa-css-prefix}-5x { font-size: 5em; } 14 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code07/num.go: -------------------------------------------------------------------------------- 1 | //数值示例 2 | package main 3 | 4 | import "fmt" 5 | 6 | func main() { 7 | //float 8 | var a = 10.2 9 | //float 10 | var b = 9.0 11 | //int 12 | //var b1 = 9 13 | //float64和int类型不匹配 14 | //var c = a * b1 15 | var c = a * b 16 | var d int 17 | var f float32 18 | fmt.Printf("类型%T,值%#v\n", a, a) 19 | fmt.Printf("类型%T,值%#v\n", c, c) 20 | fmt.Printf("类型%T,值%#v\n", b, b) 21 | fmt.Printf("类型%T,值%#v\n", d, d) 22 | fmt.Printf("类型%T,值%#v\n", f, f) 23 | } 24 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/scss/_larger.scss: -------------------------------------------------------------------------------- 1 | // Icon Sizes 2 | // ------------------------- 3 | 4 | /* makes the font 33% larger relative to the icon container */ 5 | .#{$fa-css-prefix}-lg { 6 | font-size: (4em / 3); 7 | line-height: (3em / 4); 8 | vertical-align: -15%; 9 | } 10 | .#{$fa-css-prefix}-2x { font-size: 2em; } 11 | .#{$fa-css-prefix}-3x { font-size: 3em; } 12 | .#{$fa-css-prefix}-4x { font-size: 4em; } 13 | .#{$fa-css-prefix}-5x { font-size: 5em; } 14 | -------------------------------------------------------------------------------- /go.introduce/chapter04/code06/main.go: -------------------------------------------------------------------------------- 1 | //switch不带表达式示例 2 | package main 3 | 4 | import ( 5 | "fmt" 6 | ) 7 | 8 | //审批流程 9 | func approve(days int) string { 10 | switch { 11 | case days > 3: 12 | { 13 | return "总经理审批" 14 | } 15 | default: 16 | { 17 | return "HR审批" 18 | } 19 | } 20 | } 21 | func main() { 22 | days := 3 23 | ret := approve(days) 24 | fmt.Printf("请假%d天,需要%s\n", days, ret) 25 | days = 5 26 | ret = approve(days) 27 | fmt.Printf("请假%d天,需要%s\n", days, ret) 28 | } 29 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code10/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func sum(arr [100]int) int { 8 | length := len(arr) 9 | sum := 0 10 | for i := 0; i < length; i++ { 11 | sum += arr[i] 12 | } 13 | return sum 14 | } 15 | func main() { 16 | //length := 100 17 | //var arr [length]int 必须是常量 18 | var arr [100]int 19 | length := len(arr) 20 | for i := 1; i <= length; i++ { 21 | arr[i-1] = i 22 | } 23 | sum := sum(arr) //5050 24 | fmt.Println(sum) 25 | 26 | } 27 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code08/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | //匿名struct 8 | var config struct { 9 | uid string 10 | pwd string 11 | url string 12 | } 13 | 14 | func main() { 15 | config.uid = "sa" 16 | config.pwd = "123#@" 17 | config.url = "127.0.0.1:3306" 18 | fmt.Printf("%T", config) 19 | //定义且要初始化 20 | config2 := struct { 21 | uid string 22 | pwd string 23 | url string 24 | }{"sa", "123#@", "127.0.0.1:3306"} 25 | fmt.Printf("%T", config2) 26 | } 27 | -------------------------------------------------------------------------------- /go.introduce/chapter04/code07/main.go: -------------------------------------------------------------------------------- 1 | //for示例 2 | package main 3 | 4 | import ( 5 | "fmt" 6 | ) 7 | 8 | func main() { 9 | for i := 0; i < 10; i++ { 10 | fmt.Printf("%d\n", i) 11 | } 12 | fmt.Println("==========") 13 | j := 10 14 | for j > 0 { 15 | fmt.Printf("--%d\n", j) 16 | j-- 17 | 18 | } 19 | fmt.Println("==========") 20 | s := 10 21 | for { 22 | if s == 0 { 23 | goto label 24 | } 25 | s-- 26 | fmt.Printf("%d\n", s) 27 | } 28 | label: 29 | fmt.Printf("%d\n", j) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code09/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | _ "net/http/pprof" //开启pprof 6 | "time" 7 | ) 8 | 9 | func getMsg() string { 10 | time.Sleep(1 * time.Second) 11 | return "Hello" 12 | 13 | } 14 | 15 | //http://127.0.0.1:8080/debug/pprof/ 16 | func main() { 17 | http.HandleFunc("/", homeHandler) 18 | http.ListenAndServe("0.0.0.0:8080", nil) 19 | } 20 | func homeHandler(w http.ResponseWriter, r *http.Request) { 21 | msg := getMsg() 22 | w.Write([]byte(msg)) 23 | } 24 | -------------------------------------------------------------------------------- /go.introduce/chapter03/code09/func.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type callback func(int, int) int 6 | 7 | func doAdd(a, b int, f callback) int { 8 | fmt.Println("f callback") 9 | return f(a, b) 10 | } 11 | func add(a, b int) int { 12 | fmt.Println("add running") 13 | return a + b 14 | } 15 | 16 | func main() { 17 | a, b := 2, 3 18 | fmt.Println(doAdd(a, b, add)) 19 | 20 | fmt.Println(doAdd(a, b, func(a int, b int) int { 21 | fmt.Println("============") 22 | return a * b 23 | })) 24 | } 25 | -------------------------------------------------------------------------------- /go.introduce/chapter04/code09/main.go: -------------------------------------------------------------------------------- 1 | //error示例 2 | package main 3 | 4 | import ( 5 | "errors" 6 | "fmt" 7 | ) 8 | 9 | //倒数 10 | func reciprocal(n int) (float64, error) { 11 | if n == 0 { 12 | return 0, errors.New("0不能求倒数") 13 | } 14 | //不是float64(1/n) 15 | return float64(1) / float64(n), nil 16 | } 17 | func main() { 18 | for i := 3; i >= 0; i-- { 19 | ret, err := reciprocal(i) 20 | if err != nil { 21 | fmt.Println(err) 22 | } else { 23 | fmt.Printf("1/%d = %.3f\n", i, ret) 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /go.introduce/chapter04/code10/main.go: -------------------------------------------------------------------------------- 1 | //panic示例 2 | package main 3 | 4 | import ( 5 | "fmt" 6 | ) 7 | 8 | //当捕获panic异常时触发 9 | func doPanic() { 10 | err := recover() //recover捕获panic异常 11 | if err != nil { 12 | //runtime error: integer divide by zero 13 | fmt.Println("doPanic()捕获到异常:", err) 14 | } 15 | } 16 | func main() { 17 | //注册捕获异常的处理函数 18 | defer doPanic() 19 | n := 0 20 | ret := 1 / n //抛出panic异常,不能直接写1/0,编码阶段报错 21 | //defer doPanic()//必须先注册 22 | fmt.Println("main ret =", ret) //panic异常后不会打印 23 | } 24 | -------------------------------------------------------------------------------- /go.introduce/chapter08/code02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "io/ioutil" 7 | ) 8 | 9 | func main() { 10 | //根据参数进行提取 11 | //go run .\main.go -fpath hello.txt 12 | fptr := flag.String("fpath", "hello.txt", "-fpath指定文件路径读取") 13 | flag.Parse() 14 | //文件读取到内存中,一般为小文件 15 | content, err := ioutil.ReadFile(*fptr) 16 | if err != nil { 17 | fmt.Println("文件读取失败:", err) 18 | return 19 | } else { 20 | //[]byte转string 21 | fmt.Println("文件内容为:", string(content)) 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code05/main7.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | //只写通道参数 8 | func generate(ch chan<- int) { 9 | for i := 0; i < 10; i++ { 10 | ch <- i 11 | } 12 | close(ch) 13 | } 14 | 15 | //只读通道参数 16 | func square(ch <-chan int) { 17 | for n := range ch { 18 | fmt.Printf("square(%d)=%d\n", n, n*n) 19 | } 20 | } 21 | func main() { 22 | //用通道实现2个goroutine间通信 23 | ch := make(chan int) 24 | go generate(ch) 25 | go square(ch) 26 | var input string 27 | fmt.Scanln(&input) 28 | } 29 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/less/list.less: -------------------------------------------------------------------------------- 1 | // List Icons 2 | // ------------------------- 3 | 4 | .@{fa-css-prefix}-ul { 5 | padding-left: 0; 6 | margin-left: @fa-li-width; 7 | list-style-type: none; 8 | > li { position: relative; } 9 | } 10 | .@{fa-css-prefix}-li { 11 | position: absolute; 12 | left: -@fa-li-width; 13 | width: @fa-li-width; 14 | top: (2em / 14); 15 | text-align: center; 16 | &.@{fa-css-prefix}-lg { 17 | left: (-@fa-li-width + (4em / 14)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/scss/_list.scss: -------------------------------------------------------------------------------- 1 | // List Icons 2 | // ------------------------- 3 | 4 | .#{$fa-css-prefix}-ul { 5 | padding-left: 0; 6 | margin-left: $fa-li-width; 7 | list-style-type: none; 8 | > li { position: relative; } 9 | } 10 | .#{$fa-css-prefix}-li { 11 | position: absolute; 12 | left: -$fa-li-width; 13 | width: $fa-li-width; 14 | top: (2em / 14); 15 | text-align: center; 16 | &.#{$fa-css-prefix}-lg { 17 | left: -$fa-li-width + (4em / 14); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /go.introduce/chapter01/code02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | fmt.Printf("Exit自动退出程序\n") 11 | f := bufio.NewReader(os.Stdin) //读取输入的内容 12 | input := "" 13 | str := "" 14 | for { 15 | fmt.Print(">") 16 | input, _ = f.ReadString('\n') //\n行分隔符 17 | if len(input) == 1 { 18 | continue //空行继续输入 19 | } 20 | fmt.Sscan(input, &str) //移除换行 21 | if str == "exit" { 22 | break 23 | } else { 24 | fmt.Printf("输入%s\n", str) 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /go.introduce/chapter03/code04/func.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | //全局变量 6 | var cname = "jack" 7 | var age = 31 8 | 9 | func printName() { 10 | //局部变量 11 | var cname = "smith" 12 | fmt.Printf("printName cname->%s\n", cname) 13 | age++ //单独一行 14 | fmt.Printf("printName age->%d\n", age) //32 15 | //fmt.Printf("printName age->%s\n", age++) //error 16 | } 17 | func main() { 18 | printName() 19 | fmt.Printf("main cname->%s\n", cname) 20 | fmt.Printf("main age->%d\n", age) //32 21 | } 22 | -------------------------------------------------------------------------------- /go.introduce/chapter06/code09/linklist/linklist_insert.go: -------------------------------------------------------------------------------- 1 | package linklist 2 | 3 | import "errors" 4 | 5 | //Insert 节点插入,i是节点索引,从0开始;node是需要插入的节点 6 | func (this *LinkList) Insert(i uint, node *ListNode) error { 7 | if i < 0 || node == nil || i > this.length { 8 | return errors.New("节点为空或越界") 9 | } 10 | //从head依次循环定位到索引i 11 | curNode := (*this).head 12 | for j := uint(0); j < i; j++ { 13 | curNode = curNode.GetNext() 14 | } 15 | node.next = curNode.GetNext() 16 | curNode.next = node 17 | this.length++ 18 | return nil 19 | } 20 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code05/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | "sync" 7 | ) 8 | 9 | func main() { 10 | runtime.GOMAXPROCS(4) 11 | var counter = 0 //共享变量实现goroutine通讯 12 | var mlock sync.Mutex //互斥锁 13 | func() { 14 | for i := 0; i < 1000; i++ { 15 | go func() { 16 | mlock.Lock() //加锁 17 | counter++ 18 | mlock.Unlock() //解锁 19 | }() 20 | } 21 | }() 22 | fmt.Println("执行完成,按任意键退出") 23 | var input string 24 | fmt.Scanln(&input) //阻塞等待用户输入 25 | fmt.Println(counter) //1000 26 | } 27 | -------------------------------------------------------------------------------- /go.introduce/chapter04/code05/main.go: -------------------------------------------------------------------------------- 1 | //case多个表达式示例 2 | package main 3 | 4 | import ( 5 | "fmt" 6 | ) 7 | 8 | func getQuarter(m int) string { 9 | switch m { 10 | case 1, 2, 3: 11 | { 12 | return "第一季度" 13 | } 14 | case 4, 5, 6: 15 | { 16 | return "第二季度" 17 | } 18 | case 7, 8, 9: 19 | { 20 | return "第三季度" 21 | } 22 | case 10, 11, 12: 23 | { 24 | return "第四季度" 25 | } 26 | 27 | } 28 | return "参数必须1-12" 29 | } 30 | func main() { 31 | m := 7 32 | //7月是第三季度 33 | fmt.Printf("%d月是%s\n", m, getQuarter(m)) 34 | 35 | } 36 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code04/main6.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | "sync" 7 | ) 8 | 9 | func main() { 10 | runtime.GOMAXPROCS(4) 11 | var counter = 0 //共享变量实现goroutine通讯 12 | var mlock sync.Mutex //互斥锁 13 | func() { 14 | for i := 0; i < 1000; i++ { 15 | go func() { 16 | mlock.Lock() //加锁 17 | counter++ 18 | mlock.Unlock() //解锁 19 | }() 20 | } 21 | }() 22 | fmt.Println("执行完成,按任意键退出") 23 | var input string 24 | fmt.Scanln(&input) //阻塞等待用户输入 25 | fmt.Println(counter) //1000 26 | } 27 | -------------------------------------------------------------------------------- /go.introduce/chapter10/code05/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | ) 7 | 8 | type Student struct { 9 | id string 10 | Name string 11 | Age int 12 | } 13 | 14 | func main() { 15 | stu := Student{Name: "Jack", Age: 25} 16 | //参数必须为指针地址 17 | v2 := reflect.ValueOf(&stu.Name) 18 | v2.Elem().SetString("Jack2") 19 | fmt.Println(stu) 20 | v2 = reflect.ValueOf(&stu.Age) 21 | v2.Elem().SetInt(33) 22 | //包外不能进行私有变量访问 23 | v2 = reflect.ValueOf(&stu.id) 24 | v2.Elem().SetString("001") 25 | fmt.Println(stu) 26 | } 27 | -------------------------------------------------------------------------------- /go.introduce/chapter03/code12/calc/calc.go: -------------------------------------------------------------------------------- 1 | package calc 2 | 3 | import "fmt" 4 | 5 | const title = "原子计算器2.0,输入质子、中子和电子的值,得到原子序数、原子质量和电荷" 6 | const useage = "用法:空格分隔3个数值,换行进行计算。例如 16 16 18" 7 | 8 | //自动调用 9 | func init() { 10 | fmt.Println(title) 11 | fmt.Println(useage) 12 | fmt.Println("================") 13 | } 14 | 15 | //AtomCalc 计算函数 16 | // 17 | //输入p, n, e返回Z, A, c 18 | func AtomCalc(p, n, e int) (int, int, int) { 19 | //原子序数(Z) 20 | Z := p 21 | //原子质量 22 | A := p + n 23 | //电荷 24 | c := p - e 25 | //多返回值 26 | return Z, A, c 27 | 28 | } 29 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/less/core.less: -------------------------------------------------------------------------------- 1 | // Base Class Definition 2 | // ------------------------- 3 | 4 | .@{fa-css-prefix} { 5 | display: inline-block; 6 | font: normal normal normal @fa-font-size-base/@fa-line-height-base FontAwesome; // shortening font declaration 7 | font-size: inherit; // can't have font-size inherit on line above, so need to override 8 | text-rendering: auto; // optimizelegibility throws things off #1094 9 | -webkit-font-smoothing: antialiased; 10 | -moz-osx-font-smoothing: grayscale; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code07/str.go: -------------------------------------------------------------------------------- 1 | //字符串示例 2 | package main 3 | 4 | import "fmt" 5 | 6 | func main() { 7 | var msg = "I'm here \n ========" 8 | //字符串是只读的 9 | //msg[0] = "i" 10 | var msg2 = `"Hello \n Go 11 | Hello VSCode" 12 | ` 13 | var ch = 'a' //97 14 | //变量名建议不用下划线_连接,即msg_copy 15 | var msgCopy string //字符串零值"",不是nil 16 | fmt.Printf("类型%T,值%#v\n", msg, msg) 17 | fmt.Printf("类型%T,值%v\n", msg2, msg2) 18 | fmt.Printf("类型%T,值%c\n", ch, ch) 19 | //不能获取msg[0]的地址 20 | //fmt.Println(&msg[0]) 21 | fmt.Printf("类型%T,值%#v\n", msgCopy, msgCopy) 22 | } 23 | -------------------------------------------------------------------------------- /go.introduce/chapter04/code04/main.go: -------------------------------------------------------------------------------- 1 | //swith fallthrough示例 2 | package main 3 | 4 | import ( 5 | "fmt" 6 | ) 7 | 8 | func getSex(code int) string { 9 | ret := "" 10 | switch code { 11 | case 1: 12 | ret += "男" 13 | fallthrough //只能放于下面 14 | case 0: 15 | ret += "女" 16 | fallthrough 17 | default: 18 | ret += "未知" 19 | } 20 | return ret 21 | } 22 | func main() { 23 | code := 1 24 | ret := getSex(code) 25 | fmt.Printf("%d->%s\n", code, ret) //1->男女未知 26 | code = 0 27 | ret = getSex(code) 28 | fmt.Printf("%d->%s\n", code, ret) //0->女未知 29 | } 30 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code03/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "go.introduce/chapter07/code03/entity" 4 | 5 | func main() { 6 | name := "A6L" 7 | aoDi := entity.AoDi{} 8 | aoDi.Drive(name) //Drive AoDi A6L Car 9 | //值接收者实现的接口可以传递实体类型的地址或者实体类型 10 | mycar := entity.MyCar{&aoDi} //ok 11 | //mycar := entity.MyCar{aoDi} 12 | mycar.Drive(name) //Drive AoDi A6L Car 13 | name = "X6" 14 | //指针接收者实现的接口必须传递实体类型的地址 15 | mycar = entity.MyCar{&entity.BMW{}} 16 | mycar.Drive(name) //Drive BMW X6 Car 17 | 18 | mycar.IDrive.Drive(name) //Drive BMW X6 Car 19 | 20 | } 21 | -------------------------------------------------------------------------------- /go.introduce/chapter10/code10/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "go.introduce/chapter10/code10/entity" 7 | "go.introduce/chapter10/code10/ydorm" 8 | ) 9 | 10 | func main() { 11 | stu := entity.Student{ 12 | Id: "001", 13 | Name: "Jack", 14 | Age: 25, 15 | Sex: "男", 16 | } 17 | if isOk, _ := ydorm.Save(&stu); isOk { 18 | fmt.Println("新增成功") 19 | } 20 | if isOk, _ := ydorm.Update(&stu); isOk { 21 | fmt.Println("更新成功") 22 | } 23 | if isOk, _ := ydorm.Delete(&stu); isOk { 24 | fmt.Println("删除成功") 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code02/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "html/template" 6 | "net/http" 7 | ) 8 | 9 | type Data struct { 10 | Msg string //首字母大写 11 | } 12 | 13 | // 返回静态html 14 | func handleIndex(writer http.ResponseWriter, request *http.Request) { 15 | t, _ := template.ParseFiles("index.html") 16 | data := Data{Msg: "Hello HTTP"} 17 | t.Execute(writer, data) //赋值 18 | } 19 | func main() { 20 | http.HandleFunc("/", handleIndex) 21 | err := http.ListenAndServe(":8080", nil) 22 | if err != nil { 23 | fmt.Println(err) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/scss/_core.scss: -------------------------------------------------------------------------------- 1 | // Base Class Definition 2 | // ------------------------- 3 | 4 | .#{$fa-css-prefix} { 5 | display: inline-block; 6 | font: normal normal normal #{$fa-font-size-base}/#{$fa-line-height-base} FontAwesome; // shortening font declaration 7 | font-size: inherit; // can't have font-size inherit on line above, so need to override 8 | text-rendering: auto; // optimizelegibility throws things off #1094 9 | -webkit-font-smoothing: antialiased; 10 | -moz-osx-font-smoothing: grayscale; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code12/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | //printArr 打印[2][3]int数组 8 | func printArr(arr [2][3]int) { 9 | for i := 0; i < len(arr); i++ { 10 | for j := 0; j < len(arr[0]); j++ { 11 | fmt.Print(arr[i][j], " ") 12 | } 13 | fmt.Println() 14 | } 15 | } 16 | func main() { 17 | var twoArr [2][3]int 18 | twoArr[0][0] = 1 19 | twoArr[1][1] = 2 20 | twoArr[1][2] = 3 21 | printArr(twoArr) 22 | //定义并初始化 23 | arr2 := [2][3]int{ 24 | {1, 2, 3}, 25 | {4, 5, 6}, //,不能省略 26 | } 27 | fmt.Println(arr2[1][2]) //6 28 | } 29 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/scss/font-awesome.scss: -------------------------------------------------------------------------------- 1 | /*! 2 | * Font Awesome 4.7.0 by @davegandy - http://fontawesome.io - @fontawesome 3 | * License - http://fontawesome.io/license (Font: SIL OFL 1.1, CSS: MIT License) 4 | */ 5 | 6 | @import "variables"; 7 | @import "mixins"; 8 | @import "path"; 9 | @import "core"; 10 | @import "larger"; 11 | @import "fixed-width"; 12 | @import "list"; 13 | @import "bordered-pulled"; 14 | @import "animated"; 15 | @import "rotated-flipped"; 16 | @import "stacked"; 17 | @import "icons"; 18 | @import "screen-reader"; 19 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code07/var.go: -------------------------------------------------------------------------------- 1 | //变量示例 2 | package main 3 | 4 | import "fmt" 5 | 6 | func main() { 7 | var ver string = "1.0.0" 8 | var author = "jackwang" 9 | time := "2019-12-1" 10 | //一行多个变量 11 | var a, b int = 1, 2 12 | var ( 13 | A string = "0" 14 | B = "1" 15 | ) 16 | fmt.Printf("类型%T,值%s \n", ver, ver) 17 | fmt.Printf("类型%T,值%s \n", author, author) 18 | fmt.Printf("类型%T,值%s \n", time, time) 19 | fmt.Printf("类型%T,值%d \n", a, a) 20 | fmt.Printf("类型%T,值%d \n", b, b) 21 | fmt.Printf("类型%T,值%s \n", A, A) 22 | fmt.Printf("类型%T,值%s \n", B, B) 23 | } 24 | -------------------------------------------------------------------------------- /go.introduce/chapter06/code09/linklist/linklist.go: -------------------------------------------------------------------------------- 1 | //Go单链表实现 2 | package linklist 3 | 4 | import ( 5 | "fmt" 6 | ) 7 | 8 | type LinkList struct { 9 | head *ListNode 10 | length uint 11 | } 12 | 13 | //CreateLinkList 初始化单链表 14 | func CreateLinkList() *LinkList { 15 | return &LinkList{ 16 | head: &ListNode{0, nil}, 17 | length: 0, 18 | } 19 | } 20 | 21 | //PrintLink 打印链表 22 | func (this *LinkList) PrintLink() { 23 | cur := this.head.GetNext() 24 | for nil != cur { 25 | fmt.Printf("%v->", cur.GetValue()) 26 | cur = cur.GetNext() 27 | } 28 | fmt.Println() 29 | } 30 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code05/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Go SSE 6 | 7 |

Go SSE

8 |
9 | 10 | 11 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /go.introduce/chapter06/code02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | 9 | var a int64 = 8 10 | var ptr *int64 = &a 11 | fmt.Printf("%v\n", ptr) 12 | //通过指针修改值 13 | *ptr = 9 14 | fmt.Printf("%v\n", a) //9 15 | var c float32 = 3.14 16 | //ptr := &c //*float32和*int64类型不兼容 17 | ptr2 := &c 18 | fmt.Printf("%v\n", ptr2) 19 | fmt.Printf("%v\n", c) //3.14 20 | c = 6.28 21 | fmt.Printf("%v\n", *ptr2) //6.28 22 | 23 | d := new(int) //开辟内存,d是*int 24 | fmt.Printf("%v\n", *d) //0 25 | *d = 9 26 | fmt.Printf("%v\n", *d) //9 27 | } 28 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code07/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${file}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter09/code08/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${file}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter09/code09/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${file}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter01/code02/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter02/code06/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter02/code07/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter02/code08/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter03/code01/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter03/code02/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter03/code03/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter03/code04/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter03/code05/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter03/code06/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter03/code07/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter03/code08/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter03/code09/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter03/code10/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter03/code11/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter03/code12/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter04/code01/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter04/code02/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter04/code03/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter04/code04/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter04/code05/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter04/code06/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter04/code07/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter04/code08/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter04/code09/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter04/code10/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter04/code11/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code01/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code02/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code03/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code04/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code05/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code05/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | //Student 学生结构 8 | type Student struct { 9 | XH string 10 | Name string 11 | Age int 12 | Height float32 13 | Class string 14 | } 15 | 16 | func change(stu Student) { 17 | stu.Name = "Smith" 18 | stu.Age = 22 19 | fmt.Printf("%+v", stu) 20 | fmt.Println() 21 | } 22 | func main() { 23 | stu2 := Student{} 24 | stu2.XH = "064248" 25 | stu2.Name = "jack" 26 | stu2.Age = 32 27 | stu2.Height = 1.7 28 | stu2.Class = "3" 29 | change(stu2) 30 | fmt.Printf("%+v", stu2) 31 | 32 | } 33 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code06/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code07/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code08/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code09/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code10/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code11/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code12/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code13/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code14/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code15/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code16/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code17/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code18/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code19/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code20/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code21/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code22/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter05/code23/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter06/code01/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter06/code02/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter06/code03/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter06/code04/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter06/code05/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter06/code06/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter06/code07/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter06/code08/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter06/code09/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter07/code01/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter07/code02/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter07/code03/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter07/code04/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter07/code05/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter07/code06/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter07/code07/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter08/code01/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter08/code02/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter08/code03/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter08/code04/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter08/code05/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter08/code06/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter08/code07/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter08/code08/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter08/code09/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter08/code10/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter08/code11/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter09/code01/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter09/code02/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter09/code03/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter09/code04/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter09/code05/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter09/code06/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter09/code10/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter10/code01/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter10/code02/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter10/code03/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter10/code04/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter10/code05/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter10/code06/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter10/code07/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter10/code08/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter10/code09/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter10/code10/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter11/code01/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter11/code02/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter11/code03/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter11/code04/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter11/code05/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter12/chat/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | "program": "${fileDirname}", 13 | "env": {}, 14 | "args": [] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /go.introduce/chapter09/code06/main7.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | "time" 7 | ) 8 | 9 | //goroutine泄漏,只发送没有接收 10 | func consumer(ch chan int) { 11 | for { 12 | data := <-ch 13 | fmt.Println(data) 14 | } 15 | } 16 | func main() { 17 | ch := make(chan int) 18 | for { 19 | //模拟持续运行 20 | time.Sleep(1 * time.Second) 21 | go consumer(ch) 22 | //goroutine数量 23 | fmt.Println("goroutines:", runtime.NumGoroutine()) 24 | buf := make([]byte, 10000) 25 | runtime.Stack(buf, true) 26 | fmt.Println(string(buf)) 27 | fmt.Println(string(buf)) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /go.introduce/chapter06/code09/linklist/linklist_delete.go: -------------------------------------------------------------------------------- 1 | package linklist 2 | 3 | import "errors" 4 | 5 | func (this *LinkList) Delete(node *ListNode) error { 6 | if nil == node { 7 | return errors.New("节点为空") 8 | } 9 | pre := this.head 10 | cur := this.head.GetNext() //头指向的节点 11 | //循环直到链表尾端nil 12 | for nil != cur { 13 | if cur.GetValue() == node.GetValue() { 14 | break 15 | } 16 | pre = cur 17 | cur = cur.GetNext() 18 | } 19 | if nil == cur { 20 | return errors.New("未找到节点") 21 | } 22 | pre.next = cur.GetNext() 23 | node = nil //删除节点 24 | this.length-- 25 | return nil 26 | } 27 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code08/main3.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type BeforeSave func() 4 | 5 | //Student 学生结构 6 | type Student struct { 7 | XH string 8 | Name string 9 | Age int 10 | Height float32 11 | Class string 12 | //匿名字段(函数类型) 13 | BeforeSave 14 | } 15 | 16 | func (s Student) Save() int { 17 | if s.BeforeSave != nil { 18 | s.BeforeSave() 19 | } 20 | println("=======save========", s.Name) 21 | return 1 22 | } 23 | func main() { 24 | 25 | var stu = Student{} 26 | stu.BeforeSave = func() { 27 | println("=======before save========") 28 | 29 | } 30 | println(stu.Save()) 31 | } 32 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code13/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | //Student 学生结构 9 | type Student struct { 10 | XH string 11 | Name string 12 | Age int 13 | Height float32 14 | Class string 15 | } 16 | 17 | func main() { 18 | 19 | arr := [10]Student{} 20 | for i := 0; i < len(arr); i++ { 21 | arr[i] = Student{ 22 | XH: "XH" + strconv.Itoa(i), 23 | Name: "Jack" + strconv.Itoa(i), 24 | Age: 10 + i, 25 | Class: strconv.Itoa(i), 26 | } 27 | } 28 | //Jack1 29 | fmt.Println(arr[1].Name) 30 | //12 31 | fmt.Println(arr[2].Age) 32 | } 33 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code22/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | 9 | slice := []int{1, 2, 3} 10 | //v是副本 11 | for _, v := range slice { 12 | v = v * 2 13 | } 14 | fmt.Println(slice) //[1 2 3] 15 | //循环可追加 16 | for _, v := range slice { 17 | slice = append(slice, v) 18 | } 19 | //[1 2 3 1 2 3] 20 | fmt.Println(slice) 21 | map1 := map[string]string{ 22 | "name": "jack", 23 | "xh": "064248", 24 | } 25 | for k := range map1 { 26 | if k == "xh" { 27 | //循环可以删除 28 | delete(map1, "xh") 29 | } 30 | } 31 | fmt.Println(map1) //map[name:jack] 32 | } 33 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code10/mapreduce/master.go: -------------------------------------------------------------------------------- 1 | package mapreduce 2 | 3 | import "sync" 4 | 5 | //Master 负责调度,将4个输入任务,分配到2个ReduceWorker上 6 | func Master(in []<-chan map[string]int, out [2]chan<- map[string]int) { 7 | var wg sync.WaitGroup 8 | wg.Add(len(in)) 9 | i := 0 10 | for _, ch := range in { 11 | go func(c <-chan map[string]int) { 12 | for m := range c { 13 | if i%2 == 0 { 14 | out[0] <- m 15 | } else { 16 | out[1] <- m 17 | } 18 | } 19 | wg.Done() 20 | i++ 21 | }(ch) 22 | 23 | } 24 | go func() { 25 | wg.Wait() 26 | close(out[0]) 27 | close(out[1]) 28 | }() 29 | } 30 | -------------------------------------------------------------------------------- /go.introduce/chapter12/ChatClient/ChatClient/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace ChatClient 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// 应用程序的主入口点。 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new FrmChat()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code02/entity/student.go: -------------------------------------------------------------------------------- 1 | package entity 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | //继承通过组合来实现的 8 | type Student struct { 9 | //小写无法继承属性和方法 10 | //person Person 11 | Person //组合Person 12 | school string 13 | } 14 | 15 | func (this *Student) GotoSchool() { 16 | fmt.Println(this.name, "go to ", this.school) 17 | } 18 | func (this *Student) Walk() { 19 | fmt.Println(this.name, " Walk") 20 | } 21 | func (this *Student) New(name string, age int, sex string, school string) { 22 | //继承的属性 23 | this.name = name 24 | this.age = age 25 | this.sex = sex 26 | //自己的属性 27 | this.school = school 28 | 29 | } 30 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/less/stacked.less: -------------------------------------------------------------------------------- 1 | // Stacked Icons 2 | // ------------------------- 3 | 4 | .@{fa-css-prefix}-stack { 5 | position: relative; 6 | display: inline-block; 7 | width: 2em; 8 | height: 2em; 9 | line-height: 2em; 10 | vertical-align: middle; 11 | } 12 | .@{fa-css-prefix}-stack-1x, .@{fa-css-prefix}-stack-2x { 13 | position: absolute; 14 | left: 0; 15 | width: 100%; 16 | text-align: center; 17 | } 18 | .@{fa-css-prefix}-stack-1x { line-height: inherit; } 19 | .@{fa-css-prefix}-stack-2x { font-size: 2em; } 20 | .@{fa-css-prefix}-inverse { color: @fa-inverse; } 21 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code06/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | //Student 学生结构 8 | type Student struct { 9 | XH string 10 | Name string 11 | Age int 12 | Height float32 13 | Class string 14 | } 15 | 16 | //CreateNew 给Student进行初始化的方法 17 | func (stu Student) CreateNew(xh, name, class string, age int, height float32) Student { 18 | stu.XH = xh 19 | stu.Name = name 20 | stu.Age = age 21 | stu.Height = height 22 | stu.Class = class 23 | return stu 24 | } 25 | func main() { 26 | stu := Student{} 27 | stu = stu.CreateNew("064248", "jack", "3", 32, 1.7) 28 | fmt.Printf("%+v", stu) 29 | } 30 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code20/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func change(m map[string]string) { 8 | m["name"] = "Jack" 9 | } 10 | func main() { 11 | 12 | myMap := map[string]string{ 13 | "key1": "value1", 14 | "key2": "value2", 15 | } 16 | change(myMap) 17 | //map[key1:value1 key2:value2 name:Jack] 18 | fmt.Println(myMap) 19 | myMap2 := myMap 20 | delete(myMap2, "key1") 21 | //map[key2:value2 name:Jack] 22 | fmt.Println(myMap) 23 | //map[key2:value2 name:Jack] 24 | fmt.Println(myMap2) 25 | v, e := myMap2["name"] //判断键name是否存在 26 | if e { 27 | fmt.Println(v) //Jack 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/scss/_stacked.scss: -------------------------------------------------------------------------------- 1 | // Stacked Icons 2 | // ------------------------- 3 | 4 | .#{$fa-css-prefix}-stack { 5 | position: relative; 6 | display: inline-block; 7 | width: 2em; 8 | height: 2em; 9 | line-height: 2em; 10 | vertical-align: middle; 11 | } 12 | .#{$fa-css-prefix}-stack-1x, .#{$fa-css-prefix}-stack-2x { 13 | position: absolute; 14 | left: 0; 15 | width: 100%; 16 | text-align: center; 17 | } 18 | .#{$fa-css-prefix}-stack-1x { line-height: inherit; } 19 | .#{$fa-css-prefix}-stack-2x { font-size: 2em; } 20 | .#{$fa-css-prefix}-inverse { color: $fa-inverse; } 21 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/less/font-awesome.less: -------------------------------------------------------------------------------- 1 | /*! 2 | * Font Awesome 4.7.0 by @davegandy - http://fontawesome.io - @fontawesome 3 | * License - http://fontawesome.io/license (Font: SIL OFL 1.1, CSS: MIT License) 4 | */ 5 | 6 | @import "variables.less"; 7 | @import "mixins.less"; 8 | @import "path.less"; 9 | @import "core.less"; 10 | @import "larger.less"; 11 | @import "fixed-width.less"; 12 | @import "list.less"; 13 | @import "bordered-pulled.less"; 14 | @import "animated.less"; 15 | @import "rotated-flipped.less"; 16 | @import "stacked.less"; 17 | @import "icons.less"; 18 | @import "screen-reader.less"; 19 | -------------------------------------------------------------------------------- /go.introduce/chapter04/code02/main.go: -------------------------------------------------------------------------------- 1 | //if判断中的数据作用域示例 2 | package main 3 | 4 | import ( 5 | "fmt" 6 | ) 7 | 8 | //审批流程 9 | func approve(days int) string { 10 | ret := "" 11 | if days > 3 { 12 | //if括号范围内的局部变量 13 | ret2 := "=========" 14 | ret = "总经理审批" 15 | fmt.Println(ret2) 16 | } else if days <= 3 && days > 1 { 17 | ret = "HR审批" 18 | } else { //else不能换行 19 | ret = "自动审批" 20 | } 21 | //fmt.Println(ret2) 22 | return ret 23 | } 24 | func main() { 25 | days := 3 26 | ret := approve(days) 27 | fmt.Printf("请假%d天,需要%s\n", days, ret) 28 | days = 5 29 | ret = approve(days) 30 | fmt.Printf("请假%d天,需要%s\n", days, ret) 31 | } 32 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code08/main.go: -------------------------------------------------------------------------------- 1 | //原子计算器,只能进行一次计算 2 | //知道质子、中子和电子的数目,可以计算原子序数、原子质量和电荷 3 | package main 4 | 5 | import ( 6 | "fmt" 7 | ) 8 | 9 | func main() { 10 | //质子 11 | var p int = 0 12 | //中子 13 | n := 0 14 | //电子 15 | var e = 0 16 | fmt.Println("原子计算器1.0,输入质子、中子和电子的值,得到原子序数、原子质量和电荷") 17 | fmt.Println("用法:空格分隔3个数值,换行进行计算。例如 16 16 18") 18 | fmt.Println("================") 19 | //Scanln遇到换行时才停止扫描 20 | fmt.Scanln(&p, &n, &e) 21 | //原子序数(Z) 22 | Z := p 23 | //原子质量 24 | A := p + n 25 | //电荷 26 | c := p - e 27 | fmt.Printf("当质子p=%d、中子n=%d和电子e=%d时 \n", p, n, e) 28 | fmt.Printf("原子序数Z=%d、原子质量A=%d和电荷c=%d \n", Z, A, c) 29 | } 30 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code07/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | //Address 地址结构 8 | type Address struct { 9 | Province string 10 | City string 11 | Street string 12 | Other string 13 | } 14 | 15 | //Student 学生结构 16 | type Student struct { 17 | XH string 18 | Name string 19 | Age int 20 | Height float32 21 | Class string 22 | //struct嵌套 23 | Address Address 24 | } 25 | 26 | func main() { 27 | stu := Student{} 28 | stu.XH = "064248" 29 | stu.Name = "Jack" 30 | stu.Address.Province = "JS" 31 | stu.Address.City = "XZ" 32 | stu.Address.Street = "KaiYuan" 33 | fmt.Printf("%+v", stu) 34 | 35 | } 36 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code07/sql/orderby.go: -------------------------------------------------------------------------------- 1 | package sql 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | type Order string 8 | 9 | const ( 10 | ASC Order = " ASC " 11 | DESC Order = " DESC " 12 | ) 13 | 14 | type OrderByItem struct { 15 | Field string 16 | Order 17 | } 18 | 19 | func (da *DbData) GenOrderBy() string { 20 | s := make([]string, 0) 21 | for _, v := range da.OrderBy { 22 | s = append(s, DbMapLeft[da.DbType]) 23 | s = append(s, v.Field) 24 | s = append(s, DbMapRight[da.DbType]) 25 | s = append(s, string(v.Order)) //强制转换为string 26 | s = append(s, ",") 27 | 28 | } 29 | s = s[0 : len(s)-1] 30 | return strings.Join(s, "") 31 | } 32 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code15/main2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | slice := []int{1, 2, 3, 4, 5} 9 | slice2 := slice[1:3] 10 | fmt.Println(slice2) //[2 3] 11 | fmt.Println(len(slice2)) //长度2 12 | fmt.Println(cap(slice2)) //容量4 13 | fmt.Println(slice2[0]) //2 14 | fmt.Println(slice2[1]) //3 15 | //fmt.Println(slice2[2]) //下标越界 16 | //fmt.Println(slice2[3]) //下标越界 17 | slice2[0] = 9 //修改会影响slice和slice2 18 | fmt.Println(slice) //[1 9 3 4 5] 19 | fmt.Println(slice2) //[9 3] 20 | slice[0] = 7 //只会影响slice 21 | fmt.Println(slice) //[7 9 3 4 5] 22 | fmt.Println(slice2) //[9 3] 23 | } 24 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code06/main2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "net/http" 7 | ) 8 | 9 | func httpGet(url string, ch chan string) { 10 | res, err := http.Get(url) 11 | if err != nil { 12 | panic(err) 13 | } 14 | defer res.Body.Close() 15 | bs, _ := ioutil.ReadAll(res.Body) 16 | ch <- fmt.Sprintf("[%s]:%d", url, len(bs)) 17 | } 18 | func main() { 19 | urls := []string{ 20 | "http://www.jd.com", 21 | "http://www.baidu.com", 22 | } 23 | bch := make(chan string, len(urls)) 24 | for _, url := range urls { 25 | go httpGet(url, bch) 26 | } 27 | for range urls { 28 | msg := <-bch 29 | fmt.Println(msg) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code10/mapreduce/init.go: -------------------------------------------------------------------------------- 1 | package mapreduce 2 | 3 | //包内全局变量 4 | var ( 5 | size = 10 6 | chtxt1 = make(chan string, size) 7 | chtxt2 = make(chan string, size) 8 | chtxt3 = make(chan string, size) 9 | chtxt4 = make(chan string, size) 10 | chmap1 = make(chan map[string]int, size) 11 | chmap2 = make(chan map[string]int, size) 12 | chmap3 = make(chan map[string]int, size) 13 | chmap4 = make(chan map[string]int, size) 14 | chreduce1 = make(chan map[string]int, size) 15 | chreduce2 = make(chan map[string]int, size) 16 | chtemp1 = make(chan map[string]int, size) 17 | chtemp2 = make(chan map[string]int, size) 18 | ) 19 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code01/server/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | ) 6 | 7 | func main() { 8 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 9 | if r.Method == "GET" { 10 | vars := r.URL.Query() 11 | key, ok := vars["key"] 12 | if ok { 13 | msg := "hello get " + key[0] 14 | w.Write([]byte(msg)) 15 | } else { 16 | w.Write([]byte("hello world!")) 17 | } 18 | } 19 | if r.Method == "POST" { 20 | r.ParseForm() 21 | key := r.Form.Get("name") 22 | msg := "hello post " + key 23 | w.Write([]byte(msg)) 24 | } 25 | 26 | }) 27 | 28 | http.ListenAndServe("127.0.0.1:8080", nil) 29 | } 30 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code03/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | "sync" 7 | "time" 8 | 9 | "go.introduce/chapter09/code03/parallel" 10 | ) 11 | 12 | func main() { 13 | //模拟2核 14 | runtime.GOMAXPROCS(2) 15 | var wg sync.WaitGroup 16 | wg.Add(2) //等待2个协程运行完成 17 | gopher1 := parallel.Gopher{Name: "Gopher1", Id: 1} 18 | gopher2 := parallel.Gopher{Name: "Gopher2", Id: 2} 19 | t := time.Now() 20 | //gopher1和gopher2并发执行 21 | go gopher1.MakeCoffee("A", &wg) 22 | go gopher2.MakeCoffee("B", &wg) 23 | wg.Wait() 24 | elapsed := time.Since(t) 25 | fmt.Println("app elapsed:", elapsed) 26 | fmt.Println("============END===============") 27 | } 28 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code21/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | 9 | arr := [3]int{1, 2, 3} 10 | for index, v := range arr { 11 | fmt.Printf("arr[%d]->%d", index, v) 12 | fmt.Println() 13 | } 14 | 15 | slice := []int{1, 2, 3, 4, 5} 16 | for index, v := range slice { 17 | fmt.Printf("slice[%d]->%d", index, v) 18 | fmt.Println() 19 | } 20 | map1 := map[string]string{ 21 | "name": "jack", 22 | "xh": "064248", 23 | } 24 | for k, v := range map1 { 25 | fmt.Printf("map[%s]->%s", k, v) 26 | fmt.Println() 27 | } 28 | sum := 0 29 | for _, v := range arr { 30 | sum += v 31 | } 32 | fmt.Println(sum) //6 33 | } 34 | -------------------------------------------------------------------------------- /go.introduce/chapter06/code01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | var a bool = false //1Byte 9 | var b uint8 = 7 //1Byte 10 | var c uint8 = 6 //1Byte 11 | var d int64 = 8 //8Byte 12 | var e float32 = 3.14 //4Byte 13 | var f int32 = 9 //4Byte 14 | var g bool = true //1Byte 15 | var h string = "hello world" //16Byte 16 | fmt.Printf("%v\n", &a) 17 | fmt.Printf("%v\n", &b) 18 | fmt.Printf("%v\n", &c) 19 | fmt.Printf("%v\n", &d) 20 | fmt.Printf("%v\n", &e) 21 | fmt.Printf("%v\n", &f) 22 | fmt.Printf("%v\n", &g) 23 | fmt.Printf("%v\n", &h) 24 | } 25 | -------------------------------------------------------------------------------- /go.introduce/chapter08/code05/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | //根据参数进行提取,参数值有空格需要用"" 11 | //go run .\main.go -fcontent "Hello Go!" 12 | content := flag.String("fcontent", "", "-fcontent指定写入文件的内容") 13 | flag.Parse() 14 | //创建文件 15 | f, err := os.Create("hello.txt") 16 | if err != nil { 17 | fmt.Println(err) 18 | return 19 | } 20 | n, err := f.WriteString(*content) 21 | if err != nil { 22 | fmt.Println(err) 23 | f.Close() 24 | return 25 | } 26 | if n > 0 { 27 | fmt.Println("写入完成") 28 | } 29 | err = f.Close() 30 | if err != nil { 31 | fmt.Println(err) 32 | return 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code10/mapreduce/sumreduce.go: -------------------------------------------------------------------------------- 1 | package mapreduce 2 | 3 | import ( 4 | "sync" 5 | ) 6 | 7 | //SumReduce 汇总输出结果 8 | func SumReduce(in []<-chan map[string]int) map[string]int { 9 | var wg sync.WaitGroup 10 | count := map[string]int{} 11 | var mLock sync.Mutex 12 | wg.Add(len(in)) 13 | for i := 0; i < len(in); i++ { 14 | go func(n int, c <-chan map[string]int) { 15 | for m := range c { 16 | for word := range m { 17 | mLock.Lock() 18 | //concurrent map writes 19 | count[word] = count[word] + m[word] 20 | mLock.Unlock() 21 | } 22 | 23 | } 24 | wg.Done() 25 | }(i, in[i]) 26 | } 27 | wg.Wait() 28 | return count 29 | } 30 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code08/counter.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "sync" 5 | "sync/atomic" 6 | ) 7 | 8 | var mlock sync.Mutex 9 | 10 | func Counter() int32 { 11 | var counter int32 = 0 12 | var wg sync.WaitGroup 13 | for i := 0; i < 10; i++ { 14 | wg.Add(1) 15 | go func() { 16 | mlock.Lock() 17 | counter++ 18 | mlock.Unlock() 19 | wg.Done() 20 | }() 21 | } 22 | wg.Wait() 23 | return counter 24 | } 25 | func Counter2() int32 { 26 | var counter int32 = 0 27 | var wg sync.WaitGroup 28 | for i := 0; i < 10; i++ { 29 | wg.Add(1) 30 | go func() { 31 | atomic.AddInt32(&counter, 1) 32 | wg.Done() 33 | }() 34 | } 35 | wg.Wait() 36 | return counter 37 | } 38 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code10/mapreduce/mapreduce.go: -------------------------------------------------------------------------------- 1 | package mapreduce 2 | 3 | //Run 运行英文单词统计 4 | func Run(txt string) map[string]int { 5 | //1)拆分 6 | go InputSplit(txt, [4]chan<- string{chtxt1, chtxt2, chtxt3, chtxt4}) 7 | //2)Map 8 | go MapWorker(chtxt1, chmap1) 9 | go MapWorker(chtxt2, chmap2) 10 | go MapWorker(chtxt3, chmap3) 11 | go MapWorker(chtxt4, chmap4) 12 | //3)调度分派 13 | go Master([]<-chan map[string]int{chmap1, chmap2, chmap3, chmap4}, [2]chan<- map[string]int{chreduce1, chreduce2}) 14 | //4)Reduce 15 | go ReduceCountWorker(chreduce1, chtemp1) 16 | go ReduceCountWorker(chreduce2, chtemp2) 17 | //5)汇总结果 18 | return SumReduce([]<-chan map[string]int{chtemp1, chtemp2}) 19 | } 20 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code07/type_convert.go: -------------------------------------------------------------------------------- 1 | //类型转换示例 2 | package main 3 | 4 | import "fmt" 5 | 6 | func main() { 7 | //float32转int 8 | var pi float32 = 3.14 9 | p := int(pi) 10 | fmt.Println(p) //3 11 | //int转float32 12 | f := float32(p) 13 | fmt.Println(f / 2.5) // 1.2 14 | //float32转float64 15 | f64 := float64(f) 16 | fmt.Printf("%T\n", f64) //输出类型,float64 17 | fmt.Printf("%.3f\n", f64) //保留3位小数,3.000 18 | //var b bool = true 19 | //bool类型不能转int 20 | //b1 := int(b) 21 | //s := "1" 22 | //string类型不能转int 23 | //p2 := int(s) 24 | //%-10.2f表示最小10个宽度,左对齐,保留2位小数 25 | //%12.3s表示最小12个宽度,右对齐,保留3位小数 26 | //|3.14 | 3.000| 27 | fmt.Printf("|%-10.2f|%12.3f|\n", pi, f64) 28 | } 29 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code09/trace.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | "runtime/trace" 8 | "time" 9 | ) 10 | 11 | func genOne(ch chan int) { 12 | slice := make([]string, 100000) 13 | for i := 0; i < 5; i++ { 14 | ch <- i 15 | time.Sleep(1 * time.Second) 16 | slice = append(slice, slice...) 17 | } 18 | close(ch) 19 | } 20 | func main() { 21 | // go tool trace trace.out 22 | f, err := os.Create("trace.out") 23 | if err != nil { 24 | log.Fatal(err) 25 | } 26 | trace.Start(f) 27 | defer f.Close() 28 | ch := make(chan int) 29 | go genOne(ch) 30 | for c := range ch { 31 | fmt.Println(c) 32 | } 33 | defer trace.Stop() 34 | fmt.Println("Trace stopped") 35 | } 36 | -------------------------------------------------------------------------------- /go.introduce/chapter06/code05/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "unsafe" 6 | 7 | "go.introduce/chapter06/code05/entity" 8 | ) 9 | 10 | func main() { 11 | stu := new(entity.Student) //*Student 12 | //stu.id = 2 //私有不可修改 13 | fmt.Printf("%+v \n", stu) //&{name: id:0} 14 | //第一个name string类型 15 | p := (*string)(unsafe.Pointer(stu)) 16 | *p = "jack" //突破第一个私有字段 17 | fmt.Printf("%+v \n", stu) //&{name:jack id:0} 18 | //第二个,需要指针运算,第一个是字符串长度为16->uintptr(16) 19 | ptr_id := (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(stu)) + uintptr(16))) 20 | 21 | //p2 := (*int)(unsafe.Pointer(stu)) 22 | *ptr_id = 1 //突破第二个私有字段 23 | fmt.Printf("%+v \n", stu) //&{name:jack id:1} 24 | } 25 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code05/main8.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | func generate1(ch chan<- int) { 9 | time.Sleep(3 * time.Second) 10 | ch <- 7 11 | 12 | } 13 | func generate2(ch chan<- int) { 14 | time.Sleep(2 * time.Second) 15 | ch <- 8 16 | 17 | } 18 | func main() { 19 | //用通道实现2个goroutine间通信 20 | ch := make(chan int) 21 | go generate1(ch) 22 | ch2 := make(chan int) 23 | go generate2(ch2) 24 | for { 25 | select { 26 | case n1 := <-ch: 27 | fmt.Println(n1) 28 | case n2 := <-ch2: 29 | fmt.Println(n2) 30 | case <-time.After(time.Second): 31 | fmt.Println("timeout") 32 | goto EXIT //break无法退出for循环 33 | } 34 | } 35 | EXIT: 36 | var input string 37 | fmt.Scanln(&input) 38 | } 39 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code08/main2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | //Address 地址结构 8 | type Address struct { 9 | Province string 10 | City string 11 | Street string 12 | string //匿名字段,字段名和类型都是string 13 | } 14 | 15 | //Student 学生结构 16 | type Student struct { 17 | XH string 18 | Name string 19 | Age int 20 | Height float32 21 | Class string 22 | //匿名字段 23 | Address 24 | } 25 | 26 | func main() { 27 | stu := Student{ 28 | XH: "064248", 29 | Name: "Jack", 30 | Age: 32, 31 | Address: Address{ 32 | Province: "JS", 33 | City: "XZ", 34 | Street: "KaiYuan", 35 | string: "118", //换行必须末尾有, 36 | }, 37 | Height: 1.7, Class: "3", //换行必须末尾有, 38 | } 39 | fmt.Printf("%+v", stu) 40 | } 41 | -------------------------------------------------------------------------------- /go.introduce/chapter08/code04/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | ) 10 | 11 | func main() { 12 | //根据参数进行提取 13 | //go run .\main.go -fpath hello.txt 14 | fptr := flag.String("fpath", "hello.txt", "-fpath指定文件路径读取") 15 | flag.Parse() 16 | file, err := os.Open(*fptr) 17 | if err != nil { 18 | log.Fatal(err) 19 | } 20 | //关闭文件,释放资源 21 | defer func() { 22 | if err = file.Close(); err != nil { 23 | fmt.Println("文件操作失败:", err) 24 | } 25 | }() 26 | //分行读取到内存中,可以处理大文件 27 | fmt.Println("文件内容为:") 28 | sc := bufio.NewScanner(file) 29 | for sc.Scan() { 30 | fmt.Println(sc.Text()) 31 | } 32 | 33 | if err = sc.Err(); err != nil { 34 | fmt.Println("文件操作失败:", err) 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code07/opt_bit.go: -------------------------------------------------------------------------------- 1 | //位运算符示例 2 | package main 3 | 4 | import "fmt" 5 | 6 | func main() { 7 | //二进制数值表示 8 | a, b := 0b00111100, 0b10001101 9 | //&按位与运算符,参与运算的两数各对应的二进位相与 10 | fmt.Printf("%b & %b = %b \n", a, b, a&b) //111100 & 10001101 = 1100 11 | //|按位或运算符,参与运算的两数各对应的二进位相或 12 | fmt.Printf("%b | %b = %b \n", a, b, a|b) //111100 | 10001101 = 10111101 13 | //^按位异或运算符,参与运算的两数各对应的二进位相异或, 14 | //当两对应的二进位相异时,结果为1 15 | fmt.Printf("%b ^ %b = %b \n", a, b, a^b) //111100 ^ 10001101 = 10110001 16 | //<<左移运算符,左边的运算数的各二进位全部左移若干位, 17 | //<<右边的数指定移动的位数,高位丢弃,低位补0 18 | fmt.Printf("%b<<3 = %b \n", a, a<<3) //111100<<3 = 111100000 19 | //>>右移运算符,左边的运算数的各二进位全部右移若干位, 20 | //>>右边的数指定移动的位数 21 | fmt.Printf("%b>>3 = %b \n", a, a>>3) //111100>>3 = 111 22 | } 23 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/less/bordered-pulled.less: -------------------------------------------------------------------------------- 1 | // Bordered & Pulled 2 | // ------------------------- 3 | 4 | .@{fa-css-prefix}-border { 5 | padding: .2em .25em .15em; 6 | border: solid .08em @fa-border-color; 7 | border-radius: .1em; 8 | } 9 | 10 | .@{fa-css-prefix}-pull-left { float: left; } 11 | .@{fa-css-prefix}-pull-right { float: right; } 12 | 13 | .@{fa-css-prefix} { 14 | &.@{fa-css-prefix}-pull-left { margin-right: .3em; } 15 | &.@{fa-css-prefix}-pull-right { margin-left: .3em; } 16 | } 17 | 18 | /* Deprecated as of 4.4.0 */ 19 | .pull-right { float: right; } 20 | .pull-left { float: left; } 21 | 22 | .@{fa-css-prefix} { 23 | &.pull-left { margin-right: .3em; } 24 | &.pull-right { margin-left: .3em; } 25 | } 26 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code04/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type data interface{} 8 | type Car struct { 9 | Color string 10 | Brand string 11 | } 12 | 13 | func main() { 14 | slice := make([]data, 3) 15 | slice[0] = 1 // an int 16 | slice[1] = "Hello" // a string 17 | slice[2] = Car{"Red", "BMW"} //a struct 18 | 19 | for i, v := range slice { 20 | //类型断言 21 | if value, ok := v.(int); ok { 22 | fmt.Printf("slice[%d] type is int[%d]\n", i, value) 23 | } else if value, ok := v.(string); ok { 24 | fmt.Printf("slice[%d] type is string [%s]\n", i, value) 25 | } else if value, ok := v.(Car); ok { 26 | fmt.Printf("slice[%d] type is Car [%s]\n", i, value) 27 | } else { 28 | 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/less/rotated-flipped.less: -------------------------------------------------------------------------------- 1 | // Rotated & Flipped Icons 2 | // ------------------------- 3 | 4 | .@{fa-css-prefix}-rotate-90 { .fa-icon-rotate(90deg, 1); } 5 | .@{fa-css-prefix}-rotate-180 { .fa-icon-rotate(180deg, 2); } 6 | .@{fa-css-prefix}-rotate-270 { .fa-icon-rotate(270deg, 3); } 7 | 8 | .@{fa-css-prefix}-flip-horizontal { .fa-icon-flip(-1, 1, 0); } 9 | .@{fa-css-prefix}-flip-vertical { .fa-icon-flip(1, -1, 2); } 10 | 11 | // Hook for IE8-9 12 | // ------------------------- 13 | 14 | :root .@{fa-css-prefix}-rotate-90, 15 | :root .@{fa-css-prefix}-rotate-180, 16 | :root .@{fa-css-prefix}-rotate-270, 17 | :root .@{fa-css-prefix}-flip-horizontal, 18 | :root .@{fa-css-prefix}-flip-vertical { 19 | filter: none; 20 | } 21 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/scss/_bordered-pulled.scss: -------------------------------------------------------------------------------- 1 | // Bordered & Pulled 2 | // ------------------------- 3 | 4 | .#{$fa-css-prefix}-border { 5 | padding: .2em .25em .15em; 6 | border: solid .08em $fa-border-color; 7 | border-radius: .1em; 8 | } 9 | 10 | .#{$fa-css-prefix}-pull-left { float: left; } 11 | .#{$fa-css-prefix}-pull-right { float: right; } 12 | 13 | .#{$fa-css-prefix} { 14 | &.#{$fa-css-prefix}-pull-left { margin-right: .3em; } 15 | &.#{$fa-css-prefix}-pull-right { margin-left: .3em; } 16 | } 17 | 18 | /* Deprecated as of 4.4.0 */ 19 | .pull-right { float: right; } 20 | .pull-left { float: left; } 21 | 22 | .#{$fa-css-prefix} { 23 | &.pull-left { margin-right: .3em; } 24 | &.pull-right { margin-left: .3em; } 25 | } 26 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | "time" 7 | 8 | "go.introduce/chapter09/code02/onecore" 9 | ) 10 | 11 | func main() { 12 | //GOMAXPROCS 设置可同时执行的最大CPU数 13 | //模拟单核 14 | runtime.GOMAXPROCS(1) 15 | gopher1 := onecore.Gopher{Name: "Gopher1", Id: 1} 16 | gopher2 := onecore.Gopher{Name: "Gopher2", Id: 2} 17 | 18 | //gopher1和gopher2并发执行 19 | go gopher1.MakeCoffee("A") 20 | go gopher2.MakeCoffee("B") 21 | 22 | //等待,防止主协程退出,子协程也将退出 23 | time.Sleep(40 * time.Second) //10 24 | fmt.Println("============END===============") 25 | } 26 | 27 | // Gopher 1 Make Coffee A 28 | // Gopher 1 Take Coffee A 29 | // Gopher 1 Drink Coffee A 30 | // Gopher 2 Make Coffee B 31 | // Gopher 2 Take Coffee B 32 | // Gopher 2 Drink Coffee B 33 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "net/http" 7 | "strings" 8 | ) 9 | 10 | func httpGet() { 11 | resp, err := http.Get("http://127.0.0.1:8080?key=Go") 12 | if err != nil { 13 | fmt.Println(err) 14 | return 15 | } 16 | defer resp.Body.Close() 17 | body, err := ioutil.ReadAll(resp.Body) 18 | fmt.Println(string(body)) 19 | } 20 | 21 | func httpPost() { 22 | resp, err := http.Post("http://127.0.0.1:8080", 23 | "application/x-www-form-urlencoded", 24 | strings.NewReader("name=Go")) 25 | if err != nil { 26 | fmt.Println(err) 27 | return 28 | } 29 | defer resp.Body.Close() 30 | body, err := ioutil.ReadAll(resp.Body) 31 | fmt.Println(string(body)) 32 | } 33 | func main() { 34 | httpGet() 35 | httpPost() 36 | } 37 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code19/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | var myMap map[string]string 9 | //myMap["key1"] = "value1" //错误nil map 10 | fmt.Println(myMap) //map[] 11 | 12 | myMap = make(map[string]string) 13 | //新增 14 | myMap["key1"] = "value1" 15 | myMap["key2"] = "value2" 16 | //map[key1:value1 key2:value2] 17 | fmt.Println(myMap) 18 | //修改 19 | myMap["key1"] = "value2" 20 | //删除 21 | delete(myMap, "key2") 22 | fmt.Println(myMap) //map[key1:value2] 23 | //查 24 | fmt.Println(myMap["key1"]) //value2 25 | ///////////////// 26 | //字面量创建 27 | myMap2 := map[string]string{ 28 | "key1": "value1", 29 | "key2": "value2", 30 | } 31 | myMap2["key3"] = "value3" 32 | //map[key1:value1 key2:value2 key3:value3] 33 | fmt.Println(myMap2) 34 | } 35 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code06/main6.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "time" 7 | ) 8 | 9 | //只写通道参数 10 | func generate(ch chan<- int) { 11 | for i := 0; i < 10; i++ { 12 | ch <- i 13 | time.Sleep(2 * time.Second) 14 | } 15 | } 16 | 17 | //只读通道参数 18 | func square(ch <-chan int) { 19 | for { 20 | n := <-ch 21 | fmt.Printf("square(%d)=%d\n", n, n*n) 22 | } 23 | } 24 | func main() { 25 | //go如何实时监测当前进程生成的goroutine协程数量? 26 | //http://localhost:9876/debug/pprof/goroutine 27 | go func() { 28 | fmt.Println("pprof start...") 29 | //可以开一个http端口来侦听 30 | fmt.Println(http.ListenAndServe(":9876", nil)) 31 | }() 32 | 33 | //用通道实现2个goroutine间通信 34 | ch := make(chan int) 35 | go generate(ch) 36 | go square(ch) 37 | var input string 38 | fmt.Scanln(&input) 39 | 40 | } 41 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code10/mapreduce/inputsplit.go: -------------------------------------------------------------------------------- 1 | package mapreduce 2 | 3 | import "strings" 4 | 5 | //InputSplit 拆分输入为4份,进行并发计算 6 | func InputSplit(txt string, out [4]chan<- string) { 7 | txt = strings.Replace(txt, "\n", ",", -1) 8 | txt = strings.Replace(txt, ".", ",", -1) 9 | txt = strings.Replace(txt, "!", ",", -1) 10 | arr := strings.Split(txt, ",") //,分隔 11 | mod := len(arr) % 4 12 | for i := 0; i < (4 - mod); i++ { 13 | arr = append(arr, "") //凑整 14 | } 15 | lenSplit := len(arr) / 4 //获取分段的个数 16 | for i := 0; i < 4; i++ { 17 | go func(ch chan<- string, lines []string) { 18 | for _, line := range lines { 19 | word := strings.Split(line, " ") 20 | for _, w := range word { 21 | ch <- w 22 | } 23 | } 24 | close(ch) 25 | }(out[i], arr[i*lenSplit:(i+1)*lenSplit]) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /go.introduce/chapter10/code06/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | ) 7 | 8 | //Student 字段标识Tag 9 | type Student struct { 10 | id string `json:"id" iskey:"1"` 11 | Name string `json:"cname" table:"t_student"` 12 | Age int `json:"age"` 13 | } 14 | 15 | func main() { 16 | stu := Student{Name: "Jack", Age: 25} 17 | t := reflect.TypeOf(&stu).Elem() 18 | m := make(map[string]string) 19 | for i := 0; i < t.NumField(); i++ { 20 | m[t.Field(i).Name] = t.Field(i).Tag.Get("json") 21 | } 22 | fmt.Println(m) //map[Age:age Name:cname id:id] 23 | if f, ok := t.FieldByName("Name"); ok { 24 | //t_student 25 | fmt.Println("Name字段的table标识值:", f.Tag.Get("table")) 26 | } 27 | if f, ok := t.FieldByName("id"); ok { 28 | //1 29 | fmt.Println("id字段的iskey标识值:", f.Tag.Get("iskey")) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/scss/_rotated-flipped.scss: -------------------------------------------------------------------------------- 1 | // Rotated & Flipped Icons 2 | // ------------------------- 3 | 4 | .#{$fa-css-prefix}-rotate-90 { @include fa-icon-rotate(90deg, 1); } 5 | .#{$fa-css-prefix}-rotate-180 { @include fa-icon-rotate(180deg, 2); } 6 | .#{$fa-css-prefix}-rotate-270 { @include fa-icon-rotate(270deg, 3); } 7 | 8 | .#{$fa-css-prefix}-flip-horizontal { @include fa-icon-flip(-1, 1, 0); } 9 | .#{$fa-css-prefix}-flip-vertical { @include fa-icon-flip(1, -1, 2); } 10 | 11 | // Hook for IE8-9 12 | // ------------------------- 13 | 14 | :root .#{$fa-css-prefix}-rotate-90, 15 | :root .#{$fa-css-prefix}-rotate-180, 16 | :root .#{$fa-css-prefix}-rotate-270, 17 | :root .#{$fa-css-prefix}-flip-horizontal, 18 | :root .#{$fa-css-prefix}-flip-vertical { 19 | filter: none; 20 | } 21 | -------------------------------------------------------------------------------- /go.introduce/chapter02/code07/opt_num.go: -------------------------------------------------------------------------------- 1 | //算术运算符示例 2 | package main 3 | 4 | import "fmt" 5 | 6 | func main() { 7 | a, b := 11, 2 8 | //相加 + 9 | c := a + b 10 | fmt.Printf("%d+%d = %d \n", a, b, c) //11+2 = 13 11 | //相减 - 12 | c = a - b 13 | fmt.Printf("%d-%d = %d \n", a, b, c) //11-2 = 9 14 | //相乘 * 15 | c = a * b 16 | fmt.Printf("%d*%d = %d \n", a, b, c) //11*2 = 22 17 | //相除 / 保留整数 18 | c = a / b 19 | fmt.Printf("%d/%d = %d \n", a, b, c) //11/2 = 5 20 | //取余 % 21 | c = a % b 22 | fmt.Printf("%d%%%d = %d \n", a, b, c) //11%2 = 1 23 | //自增,unexpected ++ at end of statement 24 | //c = a++ 25 | a++ 26 | fmt.Printf("a++ = %d \n", a) //a++ = 12 27 | //自减 28 | a-- 29 | fmt.Printf("a-- = %d \n", a) //a-- = 11 30 | fmt.Printf("%f \n", 2.0+3) //5.000000 31 | //d := 2.0 32 | //fmt.Printf("%f \n", a+d) //类型不匹配 33 | } 34 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code09/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | //定义一个长度为3,元素类型为string的数组 9 | //初始化为string零值"" 10 | var arrName [3]string 11 | fmt.Printf("%#v", arrName) //[3]string{"", "", ""} 12 | fmt.Println() 13 | //通过下标赋值 14 | arrName[0] = "Hello" 15 | arrName[1] = "," 16 | arrName[2] = "Go" 17 | fmt.Println(arrName) //[Hello , Go] 18 | //短变量定义,长度为3,元素类型为int的数组 19 | //初始化为int零值0 20 | arrInt := [3]int{} 21 | fmt.Println(arrInt) //[0 0 0] 22 | arrInt[0] = 1 23 | arrInt[1] = 2 24 | arrInt[2] = 3 25 | //越界报错 26 | //arrInt[4] = 4 27 | fmt.Println(arrInt) //[1 2 3] 28 | //短变量定义并初始化,长度为3,元素类型为int的数组 29 | arr2 := [3]int{7, 8, 9} 30 | fmt.Println(arr2) //[7 8 9] 31 | //可以用...,会自动根据元素个数确定数组长度 32 | arr3 := [...]int{7, 8, 9, 10} 33 | fmt.Println(arr3) //[7 8 9 10] 34 | } 35 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code05/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type data interface{} 8 | type Car struct { 9 | Color string 10 | Brand string 11 | } 12 | 13 | func main() { 14 | slice := make([]data, 3) 15 | slice[0] = 1 // an int 16 | slice[1] = "Hello" // a string 17 | slice[2] = Car{"Red", "BMW"} //a struct 18 | 19 | for i, v := range slice { 20 | //v.(type)不能在switch外的任何逻辑里面使用 21 | switch value := v.(type) { 22 | case int: 23 | { 24 | fmt.Printf("slice[%d] type is int[%d]\n", i, value) 25 | } 26 | case string: 27 | { 28 | fmt.Printf("slice[%d] type is string [%s]\n", i, value) 29 | } 30 | case Car: 31 | { 32 | fmt.Printf("slice[%d] type is Car [%s]\n", i, value) 33 | } 34 | default: 35 | { 36 | 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code06/main5.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "runtime" 7 | "time" 8 | 9 | "github.com/google/gops/agent" 10 | ) 11 | 12 | //只写通道参数 13 | func generate(ch chan<- int) { 14 | for i := 0; i < 10; i++ { 15 | ch <- i 16 | time.Sleep(2 * time.Second) 17 | buf := make([]byte, 10000) 18 | runtime.Stack(buf, true) 19 | fmt.Println(string(buf)) 20 | } 21 | } 22 | 23 | //只读通道参数 24 | func square(ch <-chan int) { 25 | for { 26 | n := <-ch 27 | fmt.Printf("square(%d)=%d\n", n, n*n) 28 | } 29 | } 30 | func main() { 31 | if err := agent.Listen(agent.Options{ShutdownCleanup: true}); err != nil { 32 | log.Fatal(err) 33 | } 34 | 35 | //用通道实现2个goroutine间通信 36 | ch := make(chan int) 37 | go generate(ch) 38 | go square(ch) 39 | var input string 40 | fmt.Scanln(&input) 41 | 42 | } 43 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code09/console.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | "runtime/pprof" 8 | "time" 9 | ) 10 | 11 | func genTwo() { 12 | slice := make([]string, 1000) 13 | for i := 0; i < 5; i++ { 14 | slice = append(slice, slice...) 15 | } 16 | } 17 | func genOne(ch chan int) { 18 | slice := make([]string, 100000) 19 | for i := 0; i < 5; i++ { 20 | ch <- i 21 | time.Sleep(1 * time.Second) 22 | slice = append(slice, slice...) 23 | genTwo() 24 | } 25 | close(ch) 26 | } 27 | func main() { 28 | // go tool pprof mem.out 29 | // svg 30 | fm, err := os.Create("mem.out") 31 | if err != nil { 32 | log.Fatal(err) 33 | } 34 | defer fm.Close() 35 | ch := make(chan int) 36 | go genOne(ch) 37 | for c := range ch { 38 | fmt.Println(c) 39 | } 40 | //放到最后再执行 41 | pprof.WriteHeapProfile(fm) 42 | 43 | } 44 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | "time" 7 | 8 | "go.introduce/chapter09/code01/onecore" 9 | ) 10 | 11 | func main() { 12 | //GOMAXPROCS 设置可同时执行的最大CPU数 13 | //模拟单核 14 | runtime.GOMAXPROCS(1) 15 | gopher1 := onecore.Gopher{Name: "Gopher1", Id: 1} 16 | gopher2 := onecore.Gopher{Name: "Gopher2", Id: 2} 17 | 18 | //非并发 19 | // gopher1.MakeCoffee("A") 20 | // gopher2.MakeCoffee("B") 21 | 22 | //gopher1和gopher2并发执行 23 | go gopher1.MakeCoffee("A") 24 | go gopher2.MakeCoffee("B") 25 | 26 | //等待,防止主协程退出,子协程也将退出 27 | time.Sleep(20 * time.Second) 28 | fmt.Println("============END===============") 29 | } 30 | 31 | // Gopher 1 Make Coffee A 32 | // Gopher 2 Take Coffee A 33 | // Gopher 2 Drink Coffee A 34 | // Gopher 1 Has No Coffee to Take 35 | // Gopher 1 Has No Coffee to Drink 36 | -------------------------------------------------------------------------------- /go.introduce/chapter08/code11/property/property.go: -------------------------------------------------------------------------------- 1 | package property 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "strings" 7 | 8 | "go.introduce/charpter08/code11/myio" 9 | ) 10 | 11 | //Read 读取config.property,没有缓存 12 | func Read(key string) string { 13 | fio, err := myio.Open("config.property") 14 | if err != nil { 15 | fmt.Println(err) 16 | return "" 17 | } 18 | sc := bufio.NewScanner(fio) 19 | line := "" 20 | slice := make([]string, 2) 21 | for sc.Scan() { 22 | line = sc.Text() 23 | //注释 24 | if strings.HasPrefix(line, "#") { 25 | continue 26 | } 27 | slice = strings.Split(line, "=") 28 | if len(slice) == 2 { 29 | if strings.Trim(slice[0], " ") == key { 30 | return strings.Trim(slice[1], " ") 31 | } 32 | } 33 | } 34 | err = fio.Close() 35 | if err != nil { 36 | fmt.Println(err) 37 | 38 | } 39 | return "" 40 | } 41 | -------------------------------------------------------------------------------- /go.introduce/chapter01/cmd.txt: -------------------------------------------------------------------------------- 1 | go install github.com/stamblerre/gocode 2 | go install github.com/mdempsky/gocode 3 | go install github.com/uudashr/gopkgs/cmd/gopkgs 4 | go install github.com/ramya-rao-a/go-outline 5 | go install github.com/acroca/go-symbols 6 | go install golang.org/x/tools/cmd/guru 7 | go install golang.org/x/tools/cmd/gorename 8 | go install github.com/cweill/gotests 9 | go install github.com/fatih/gomodifytags 10 | go install github.com/josharian/impl 11 | go install github.com/davidrjenni/reftools/cmd/fillstruct 12 | go install github.com/haya14busa/goplay/cmd/goplay 13 | go install github.com/godoctor/godoctor 14 | go install github.com/rogpeppe/godef 15 | go install golang.org/x/tools/cmd/goimports 16 | go install golang.org/x/lint/golint 17 | go install golang.org/x/tools/gopls 18 | go install github.com/sqs/goreturns 19 | go install github.com\766b\go-outliner -------------------------------------------------------------------------------- /go.introduce/chapter08/code07/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "os" 7 | "strings" 8 | ) 9 | 10 | func main() { 11 | //根据参数进行提取,参数值有空格需要用"" 12 | //go run .\main.go -fcontent "Hello Go!;你好,TypeScript!" 13 | content := flag.String("fcontent", "", "-fcontent指定写入文件的内容") 14 | flag.Parse() 15 | //创建文件 16 | f, err := os.Create("hello.txt") 17 | //f, err := os.OpenFile("hello.txt", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644) 18 | if err != nil { 19 | fmt.Println(err) 20 | return 21 | } 22 | //string 转[]byte 23 | slice := strings.Split(*content, ";") 24 | for _, line := range slice { 25 | //写入行 26 | _, err := fmt.Fprintln(f, line) 27 | if err != nil { 28 | fmt.Println(err) 29 | break 30 | } 31 | } 32 | fmt.Println("写入成功") 33 | err = f.Close() 34 | if err != nil { 35 | fmt.Println(err) 36 | return 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /go.introduce/chapter09/code06/main3.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io" 7 | "os" 8 | "strconv" 9 | "time" 10 | ) 11 | 12 | //模拟输入流,每隔1秒产生一个数据 13 | func inputStream(ch chan string) { 14 | var i = 0 15 | for { 16 | ch <- strconv.Itoa(i) + "\n" 17 | time.Sleep(1 * time.Second) 18 | i++ 19 | } 20 | 21 | } 22 | 23 | //模拟输出流,并将数据流拷贝到标准输出上 24 | func outStream(ch chan string) { 25 | for { 26 | data := <-ch 27 | buf := bytes.NewBufferString(data) 28 | //Buffer实现了io.Reader接口 29 | IOCopy(buf, os.Stdout) 30 | } 31 | } 32 | func IOCopy(src io.Reader, dst io.Writer) { 33 | if _, err := io.Copy(dst, src); err != nil { 34 | fmt.Println(err) 35 | } 36 | } 37 | func main() { 38 | //用通道实现2个goroutine间通信 39 | ch := make(chan string, 2) 40 | go inputStream(ch) 41 | go outStream(ch) 42 | var input string 43 | fmt.Scanln(&input) 44 | } 45 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code03/main.go: -------------------------------------------------------------------------------- 1 | //自定义类型的方法示例 2 | package main 3 | 4 | import ( 5 | "fmt" 6 | "strconv" 7 | ) 8 | 9 | //自定义类型str和myInt 10 | type str string 11 | type myInt int 12 | 13 | //getLen str类型的方法,获取自身的长度 14 | func (m str) getLen() int { 15 | return len(m) 16 | } 17 | func (i myInt) toStr() string { 18 | return strconv.Itoa(int(i)) 19 | } 20 | 21 | //接收器类型int不合法,基础类型(basic type)不支持 22 | // func (i int) toStr() string { 23 | // return strconv.Itoa(i) 24 | // } 25 | 26 | func main() { 27 | var name str = "Jack" 28 | fmt.Printf("%d\n", name.getLen()) //4 29 | msg := "Hello," + name 30 | fmt.Printf("%T\n", msg) //main.str 31 | fmt.Printf("%d\n", msg.getLen()) //10 32 | 33 | var i myInt = 30 34 | i2 := i + 10 35 | fmt.Printf("%T\n", i2) //myInt 36 | fmt.Printf("%#v\n", i.toStr()) //"30" 37 | fmt.Printf("%#v\n", i2.toStr()) //"30" 38 | } 39 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code04/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | //Student 学生结构 8 | type Student struct { 9 | XH string 10 | Name string 11 | Age int 12 | Height float32 13 | Class string 14 | } 15 | 16 | func main() { 17 | //第1种方法 18 | var stu Student 19 | stu.Name = "Jack" 20 | fmt.Println(stu.Name, stu.Age, stu.Height) 21 | //第2种方法 22 | stu2 := Student{} 23 | stu2.XH = "064248" 24 | stu2.Name = "jack" 25 | stu2.Age = 32 26 | stu2.Height = 1.7 27 | stu2.Class = "3" 28 | fmt.Printf("%+v", stu2) 29 | fmt.Println() 30 | //第3种方法 31 | stu3 := Student{ 32 | XH: "064248", 33 | Name: "jackwang", 34 | Age: 32, 35 | Height: 1.7, 36 | Class: "3", //,不能少 37 | } 38 | fmt.Printf("%+v", stu3) 39 | fmt.Println() 40 | //第4种方法,new返回指针 41 | stu4 := new(Student) 42 | stu4.Name = "Jack2" 43 | fmt.Printf("%+v", stu4) 44 | } 45 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/less/path.less: -------------------------------------------------------------------------------- 1 | /* FONT PATH 2 | * -------------------------- */ 3 | 4 | @font-face { 5 | font-family: 'FontAwesome'; 6 | src: url('@{fa-font-path}/fontawesome-webfont.eot?v=@{fa-version}'); 7 | src: url('@{fa-font-path}/fontawesome-webfont.eot?#iefix&v=@{fa-version}') format('embedded-opentype'), 8 | url('@{fa-font-path}/fontawesome-webfont.woff2?v=@{fa-version}') format('woff2'), 9 | url('@{fa-font-path}/fontawesome-webfont.woff?v=@{fa-version}') format('woff'), 10 | url('@{fa-font-path}/fontawesome-webfont.ttf?v=@{fa-version}') format('truetype'), 11 | url('@{fa-font-path}/fontawesome-webfont.svg?v=@{fa-version}#fontawesomeregular') format('svg'); 12 | // src: url('@{fa-font-path}/FontAwesome.otf') format('opentype'); // used when developing fonts 13 | font-weight: normal; 14 | font-style: normal; 15 | } 16 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/scss/_path.scss: -------------------------------------------------------------------------------- 1 | /* FONT PATH 2 | * -------------------------- */ 3 | 4 | @font-face { 5 | font-family: 'FontAwesome'; 6 | src: url('#{$fa-font-path}/fontawesome-webfont.eot?v=#{$fa-version}'); 7 | src: url('#{$fa-font-path}/fontawesome-webfont.eot?#iefix&v=#{$fa-version}') format('embedded-opentype'), 8 | url('#{$fa-font-path}/fontawesome-webfont.woff2?v=#{$fa-version}') format('woff2'), 9 | url('#{$fa-font-path}/fontawesome-webfont.woff?v=#{$fa-version}') format('woff'), 10 | url('#{$fa-font-path}/fontawesome-webfont.ttf?v=#{$fa-version}') format('truetype'), 11 | url('#{$fa-font-path}/fontawesome-webfont.svg?v=#{$fa-version}#fontawesomeregular') format('svg'); 12 | // src: url('#{$fa-font-path}/FontAwesome.otf') format('opentype'); // used when developing fonts 13 | font-weight: normal; 14 | font-style: normal; 15 | } 16 | -------------------------------------------------------------------------------- /go.introduce/chapter07/code01/entity/person.go: -------------------------------------------------------------------------------- 1 | package entity 2 | 3 | import "fmt" 4 | 5 | type Person struct { 6 | name string 7 | age int 8 | sex string 9 | } 10 | 11 | func (this *Person) SetName(name string) { 12 | this.name = name 13 | } 14 | func (this *Person) SetAge(age int) { 15 | if age > 0 && age < 200 { 16 | this.age = age 17 | } 18 | } 19 | func (this *Person) SetSex(sex string) { 20 | if sex == "男" || sex == "女" { 21 | this.sex = sex 22 | } else { 23 | this.sex = "未知" 24 | } 25 | 26 | } 27 | func (this *Person) GetName() string { 28 | return this.name 29 | } 30 | func (this *Person) GetAge() int { 31 | return this.age 32 | } 33 | func (this *Person) GetSex() string { 34 | return this.sex 35 | } 36 | 37 | //私有方法 38 | func (p *Person) walk() { 39 | fmt.Println("Person walk") 40 | } 41 | 42 | //Eat 公有方法 43 | func (p *Person) Eat() { 44 | fmt.Println("Person Eat") 45 | } 46 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code15/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | 9 | slice := []int{1, 2, 3, 4, 5} 10 | slice2 := slice[:] //切片拷贝 11 | slice2[0] = 9 12 | slice2[4] = 7 13 | //切片共享底层数据 14 | fmt.Println(slice) //[9 2 3 4 7] 15 | fmt.Println(slice2) //[9 2 3 4 7] 16 | s3 := slice[3:] //从下标为3切到末尾 17 | fmt.Println(s3) //[4 7] 18 | fmt.Println(len(s3)) //长度2 19 | fmt.Println(cap(s3)) //容量2 20 | s3 = slice[:3] // 从0切到3(不包含3) 21 | fmt.Println(s3) //[9 2 3] 22 | fmt.Println(len(s3)) //长度3 23 | fmt.Println(cap(s3)) //容量5 24 | s3 = slice[1:4] //从下标为1开始,长度为3(4-1) 25 | fmt.Println(s3) //[2 3 4] 26 | fmt.Println(len(s3)) //长度3 27 | fmt.Println(cap(s3)) //容量4 28 | //从下标为1的元素开始切,切片的长度(3-1),容量(4-1) 29 | s3 = slice[1:3:4] 30 | fmt.Println(s3) //[2 3] 31 | fmt.Println(len(s3)) //长度2 32 | fmt.Println(cap(s3)) //容量3 33 | } 34 | -------------------------------------------------------------------------------- /go.introduce/chapter05/code14/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | //var定义 9 | var slice []string 10 | fmt.Println(len(slice)) //0 11 | fmt.Println(cap(slice)) //0 12 | fmt.Printf("%#v", slice) //[]string(nil) 13 | fmt.Println() 14 | //slice[0] = "Hello" //下标越界 15 | slice = make([]string, 6) 16 | slice[0] = "Hello" 17 | slice[5] = "Go" 18 | fmt.Printf("%#v\n", slice) //[]string{"Hello", "", "", "", "", "Go"} 19 | //切片字面量定义,注意不要指定长度,否则为数组 20 | slice2 := []int{1, 2, 3, 4, 5} 21 | slice1 := slice2 //切片赋值,共享底层数组 22 | slice1[0] = 9 //同时影响两个切片 23 | fmt.Println(slice2) //[9 2 3 4 5] 24 | //短变量定义,长度为3,容量为10 25 | slice3 := make([]int, 3, 10) 26 | fmt.Println(len(slice3)) //3 27 | fmt.Println(cap(slice3)) //10 28 | fmt.Println(slice3) //[0 0 0] 29 | slice3[0] = 1 30 | slice3[1] = 2 31 | slice3[2] = 3 32 | fmt.Println(slice3) //[1 2 3] 33 | } 34 | -------------------------------------------------------------------------------- /go.introduce/chapter10/code09/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "reflect" 7 | ) 8 | 9 | func print(msg string) { 10 | fmt.Println(msg) 11 | } 12 | func sum(a, b int) int { 13 | return a + b 14 | } 15 | func funcCall(m map[string]interface{}, fn string, ps ...interface{}) ([]reflect.Value,error) { 16 | fv := reflect.ValueOf(m[fn]) 17 | if len(ps) != fv.Type().NumIn() { 18 | err := errors.New("参数个数错误") 19 | return nil,err 20 | } 21 | in := make([]reflect.Value, len(ps)) 22 | for k, p := range ps { 23 | in[k] = reflect.ValueOf(p) 24 | } 25 | result := fv.Call(in) 26 | return result,nil 27 | } 28 | 29 | func main() { 30 | //注册函数 31 | funcs := map[string]interface{}{ 32 | "print": print, 33 | "sum": sum, 34 | } 35 | //动态调用 36 | funcCall(funcs, "print", "hello world")//hello world 37 | v, _ := funcCall(funcs, "sum", 1, 2) 38 | fmt.Println(v[0].Int()) //3 39 | } 40 | -------------------------------------------------------------------------------- /go.introduce/chapter11/code06/server/font/font-awesome/less/animated.less: -------------------------------------------------------------------------------- 1 | // Animated Icons 2 | // -------------------------- 3 | 4 | .@{fa-css-prefix}-spin { 5 | -webkit-animation: fa-spin 2s infinite linear; 6 | animation: fa-spin 2s infinite linear; 7 | } 8 | 9 | .@{fa-css-prefix}-pulse { 10 | -webkit-animation: fa-spin 1s infinite steps(8); 11 | animation: fa-spin 1s infinite steps(8); 12 | } 13 | 14 | @-webkit-keyframes fa-spin { 15 | 0% { 16 | -webkit-transform: rotate(0deg); 17 | transform: rotate(0deg); 18 | } 19 | 100% { 20 | -webkit-transform: rotate(359deg); 21 | transform: rotate(359deg); 22 | } 23 | } 24 | 25 | @keyframes fa-spin { 26 | 0% { 27 | -webkit-transform: rotate(0deg); 28 | transform: rotate(0deg); 29 | } 30 | 100% { 31 | -webkit-transform: rotate(359deg); 32 | transform: rotate(359deg); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /go.introduce/chapter08/code03/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | ) 10 | 11 | func main() { 12 | //根据参数进行提取 13 | //go run .\main.go -fpath hello.txt -flen 6 14 | fptr := flag.String("fpath", "hello.txt", "-fpath指定文件路径读取") 15 | byteLen := flag.Int("flen", 6, "-flen指定读取的字节数") 16 | flag.Parse() 17 | file, err := os.Open(*fptr) 18 | if err != nil { 19 | log.Fatal(err) 20 | } 21 | //关闭文件,释放资源 22 | defer func() { 23 | if err = file.Close(); err != nil { 24 | fmt.Println("文件操作失败:", err) 25 | } 26 | }() 27 | //文件分片读取到内存中,可以处理大文件 28 | r := bufio.NewReader(file) 29 | buffer := make([]byte, *byteLen) 30 | fmt.Println("文件内容为:") 31 | for { 32 | n, err := r.Read(buffer) 33 | if err != nil { 34 | //fmt.Println("文件读取完毕:", err) 35 | break 36 | } 37 | //fmt.Println(string(buffer)) //可能会有额外的字符 38 | fmt.Print(string(buffer[:n])) 39 | } 40 | 41 | } 42 | --------------------------------------------------------------------------------