diff --git a/blog/golang/code/src/demo.go b/blog/golang/code/src/demo.go index a34794131d378eb13be432157f80686f3f776d53..a4341c86c347f454f2e3b249a3227c052820d299 100644 --- a/blog/golang/code/src/demo.go +++ b/blog/golang/code/src/demo.go @@ -2,6 +2,6 @@ package main import "fmt" -func main(){ - fmt.Println("Hello Golang") -} \ No newline at end of file +func main() { + fmt.Println(2 + 3) +} diff --git a/blog/golang/golang-brief.md b/blog/golang/golang-brief.md deleted file mode 100644 index d14e9619fa4fc10ac5ad36486a425e642418eb9b..0000000000000000000000000000000000000000 --- a/blog/golang/golang-brief.md +++ /dev/null @@ -1,45 +0,0 @@ -# 第二章 Golang 概述 - -程序:完成某个功能的指令的集合 - -Go语言:Google公司创造的语言 - -## Go语言发展简史 - -- 2007年原型 -- 2009发布 -- 2015 Go 1.5 -- 2017 Go 1.8 -- 2017 Go 1.9 -- 2018 Go 1.10 - -课程使用的版本:1.9.2 - -## Go语言特点 - -既能有静态编译语言的安全和性能,又能达到动态语言开发维护的效率 - -``` -Go = C + Python -``` - -- 指针 -- 包:Go语言的每一个文件都要归属于一个包,能不能单独存在 -- 垃圾回收 -- 天然并发 goroutine -- 管道通信机制 -- 函数可以返回多个值 -- 切片 - -## Go语言开发工具 - -- VSCode [https://code.visualstudio.com/](https://code.visualstudio.com/) -- VSCode网页版 [https://vscode.dev/](https://vscode.dev/) -- Sublime Text [https://www.sublimetext.com/](https://www.sublimetext.com/) -- Vim -- Emacs -- Eclipse -- LiteIDE -- GoLand [https://www.jetbrains.com/go/](https://www.jetbrains.com/go/) - -建议:初学者使用文本编辑器,工作时使用IDE diff --git a/blog/golang/golang-install.md b/blog/golang/golang-install.md index 5e1982d45aeb3123cd2199450fd7c12488179f28..e995b2f0bffe404e98f19ccc7e1359a10715adbf 100644 --- a/blog/golang/golang-install.md +++ b/blog/golang/golang-install.md @@ -1,4 +1,17 @@ -# 第三章 Golang 开发环境搭建 +# 第二章 Golang 快速开始和特性 + +## Go语言开发工具 + +- VSCode [https://code.visualstudio.com/](https://code.visualstudio.com/) +- VSCode网页版 [https://vscode.dev/](https://vscode.dev/) +- Sublime Text [https://www.sublimetext.com/](https://www.sublimetext.com/) +- Vim +- Emacs +- Eclipse +- LiteIDE +- GoLand [https://www.jetbrains.com/go/](https://www.jetbrains.com/go/) + +建议:初学者使用文本编辑器,工作时使用IDE ## 安装 VSCode @@ -11,6 +24,13 @@ $ sudo launchctl list | grep ssh - 0 com.openssh.sshd ``` +> vscode快捷键: +> 快速复制一行:shift + option + 方向键向下 +> 字体大小修改:command +/- +> 注释/取消注释:command + / +> 整体向右移动 tab +> 整体向左移动 shift + tab + ## 安装 Golang SDK:Software Development Kit 软件开发工具包 @@ -111,3 +131,151 @@ demo demo.go $ ./demo Hello Golang ``` + +## Golang执行流程 + +```bash +# go build +.go 源文件 --> 【编译】 --> 可执行文件 --> 【运行】 --> 结果 + +# go run +.go 源文件 --> 【编译运行】 --> 结果 +``` + +两种执行流程的区别 + +- 源文件需要在Go开发环境中才能运行 +- 编译后生成可执行文件,可以在没有Go开发环境的机器上运行 +- 编译时,会将依赖的库文件包含到可执行文件中,所以,可执行文件比源文件大很多 + +## 编译运行 + +- 编译器将go源文件编译成可识别的二进制文件 + +1、编译 + +```bash +$ ls +demo.go + +# 直接编译文件 +$ go build demo.go + +$ ls +demo demo.go + +# 指定生成的二进制文件名 +$ go build -o run demo.go + +# windows 下需要制定后缀名 .exe +$ go build -o run.exe demo.go + +$ ls +demo demo.go run +``` + +2、运行 + +```bash +# 运行可执行文件 +./demo + +# 直接运行go源文件 +go run demo.go +``` + +## Go语言开发的特点 + +- 源文件以`.go` 为扩展名 +- Go应用程序执行入口是`main()` 方法 +- Go语言严格区分大小写 +- GO语句后不需要分号,一行写一条语句 +- Go语言`定义的变量` 或者`import的包` 没有使用到,代码不能编译通过 +- 大括号成对出现 + + +## Golang 转义字符(escape char) + +| 转义字符 | 说明 +| - | - +| `\t`| 制表位 +| `\n` | 换行符,光标移动到下一行 +| `\\` | 斜杆 +| `\"` | 引号 +| `\r` | 回车,光标移动到行首 + + +示例 + +```go +package main + +import "fmt" + +func main(){ + fmt.Println("Hello\tGolang") + // Hello Golang + + fmt.Println("Hello\nGolang") + // Hello + // Golang + + fmt.Println("Hello\rGolang") + // Golang + + fmt.Println("Hello\\Golang") + // Hello\Golang + + fmt.Println("Hello\"Golang") + // Hello"Golang +} +``` + +示例:使用一行语句输出类似表格布局的数据 + +```go +package main + +import "fmt" + +func main(){ + fmt.Println("姓名\t年龄\t籍贯\t住址\nTom\t24\t河北\t北京") + // 姓名 年龄 籍贯 住址 + // Tom 24 河北 北京 +} +``` + +## 注释 comment + +提高代码可读性 + +```go +// 行注释 + +/* 块注释 */ +``` + +推荐使用:行注释 + +## 代码风格 + +gofmt 格式化 + +```bash +# 格式化并写入原文件 +$ gofmt -w demo.go +``` + +- 正确的缩进空格 +- 函数的左大括号,放在函数名后面(不换行) +- 运算符两边加空格 +- 每行代码字符不超过80个字 + +## Golang 标准库API + +[https://studygolang.com/pkgdoc](https://studygolang.com/pkgdoc) + +``` +包 <==> 文件夹 / 原文件 / 函数 +``` + diff --git a/blog/golang/golang-start.md b/blog/golang/golang-start.md index 3d23f6985b1be9db5715ccfbe3894b615a1f09f5..d5360431242812a6a1e1ac0544b9f0e1ba6e37cf 100644 --- a/blog/golang/golang-start.md +++ b/blog/golang/golang-start.md @@ -1,7 +1,11 @@ -# 第一章 Golang开山篇 +# 第一章 Golang 概述 Go言语 Golang +Go语言:Google公司创造的语言 + +程序:完成某个功能的指令的集合 + ## 学习方向 - 区块链(分布式账本技术) @@ -18,3 +22,30 @@ Go言语 Golang - 先建立整体框架,然后细节 - 学习软件编程是在琢磨别人怎么做,而不是我认为应该怎么做的过程 + +## Go语言发展简史 + +- 2007年原型 +- 2009发布 +- 2015 Go 1.5 +- 2017 Go 1.8 +- 2017 Go 1.9 +- 2018 Go 1.10 + +课程使用的版本:1.9.2 + +## Go语言特点 + +既能有静态编译语言的安全和性能,又能达到动态语言开发维护的效率 + +``` +Go = C + Python +``` + +- 指针 +- 包:Go语言的每一个文件都要归属于一个包,能不能单独存在 +- 垃圾回收 +- 天然并发 goroutine +- 管道通信机制 +- 函数可以返回多个值 +- 切片 diff --git a/blog/golang/index.md b/blog/golang/index.md index 591d6cb783ddb23ddcae04142cf408b2d28632d6..066e7d38e25db6a4b8ff908dcb3a936691a662d5 100644 --- a/blog/golang/index.md +++ b/blog/golang/index.md @@ -2,30 +2,17 @@ 学习资料 -- 官网:[https://golang.google.cn/](https://golang.google.cn/) -- Go 语言教程 | 菜鸟教程 [https://www.runoob.com/go/go-tutorial.html](https://www.runoob.com/go/go-tutorial.html) -- 视频:[【尚硅谷】Golang入门到实战教程丨一套精通GO语言](https://www.bilibili.com/video/BV1ME411Y71o) -- TIOBE [https://www.tiobe.com/tiobe-index/](https://www.tiobe.com/tiobe-index/) -- Go网址导航 [https://hao.studygolang.com/](https://hao.studygolang.com/) - -开源图书: - -- [Go语言圣经(中文版)](https://books.studygolang.com/gopl-zh/) -- [Go语言标准库](https://books.studygolang.com/The-Golang-Standard-Library-by-Example/) -- [Go入门指南](https://github.com/unknwon/the-way-to-go_ZH_CN/blob/master/eBook/preface.md) -- [Go 程序设计](https://www.yuque.com/qyuhen/go) -- [Go语言高级编程(Advanced Go Programming)](https://chai2010.cn/advanced-go-programming-book/) -- [Go by Example 中文](https://books.studygolang.com/gobyexample/) -- [Go 语言原本](https://golang.design/under-the-hood/) -- [Go 语言高性能编程](https://geektutu.com/post/high-performance-go.html) +- 视频适合零基础:[【尚硅谷】Golang入门到实战教程](https://www.bilibili.com/video/BV1ME411Y71o) +- 视频适合有基础:[golang入门到项目实战](https://www.bilibili.com/video/BV1zR4y1t7Wj) ## 目录 -[第一章 Golang开山篇](blog/golang/golang-start.md) +[第一章 Golang 概述](blog/golang/golang-start.md) + +[第二章 Golang 快速开始和特性](blog/golang/golang-install.md) -[第二章 Golang 概述](blog/golang/golang-brief.md) -[第三章 Golang 开发环境搭建](blog/golang/golang-install.md) +https://www.bilibili.com/video/BV1ME411Y71o?p=27&spm_id_from=pageDriver&vd_source=efbb4dc944fa761b6e016ce2ca5933da -https://www.bilibili.com/video/BV1ME411Y71o?p=16&spm_id_from=pageDriver&vd_source=efbb4dc944fa761b6e016ce2ca5933da \ No newline at end of file +https://www.bilibili.com/video/BV1zR4y1t7Wj \ No newline at end of file diff --git a/doc/go.md b/doc/go.md index c4366418d555a1fcc0566484c2495bb0fc11013b..ddb91193a60f9903605a2df8a289be14af3fb10a 100644 --- a/doc/go.md +++ b/doc/go.md @@ -1,5 +1,27 @@ # Go语言 -[LeetCode Cookbook (Go)](https://books.halfrost.com/leetcode/) +## 学习笔记 +[笔记: Golang 核心编程](blog/golang/index.md) -[笔记: Golang 核心编程](blog/golang/index.md) \ No newline at end of file + +## 学习资料 + +- 官网:[https://golang.org/](https://golang.org/) +- 官网中文:[https://go-zh.org/](https://go-zh.org/) +- 官网中文:[https://golang.google.cn/](https://golang.google.cn/) +- Golang标准库文档 [https://studygolang.com/pkgdoc](https://studygolang.com/pkgdoc) +- Go 语言教程 | 菜鸟教程 [https://www.runoob.com/go/go-tutorial.html](https://www.runoob.com/go/go-tutorial.html) +- TIOBE [https://www.tiobe.com/tiobe-index/](https://www.tiobe.com/tiobe-index/) +- Go网址导航 [https://hao.studygolang.com/](https://hao.studygolang.com/) + +## 开源图书 + +- [Go语言圣经(中文版)](https://books.studygolang.com/gopl-zh/) +- [Go语言标准库](https://books.studygolang.com/The-Golang-Standard-Library-by-Example/) +- [Go入门指南](https://github.com/unknwon/the-way-to-go_ZH_CN/blob/master/eBook/preface.md) +- [Go 程序设计](https://www.yuque.com/qyuhen/go) +- [Go语言高级编程(Advanced Go Programming)](https://chai2010.cn/advanced-go-programming-book/) +- [Go by Example 中文](https://books.studygolang.com/gobyexample/) +- [Go 语言原本](https://golang.design/under-the-hood/) +- [Go 语言高性能编程](https://geektutu.com/post/high-performance-go.html) +- [LeetCode Cookbook (Go)](https://books.halfrost.com/leetcode/)