```
docs(day01): 添加课程文档和示例代码 - 添加 .gitignore 文件忽略编译产物 - 更新 README.md 将课程内容链接到具体章节 - 新增 env/README.md 环境搭建指南,包含 Docker、Go语言安装和IDE配置 - 新增 hello_world/README.md Go语言基础教程和hello world程序详解 - 添加 hello_world/main.go 示例代码 ```
This commit is contained in:
parent
eeae40755e
commit
1d62dac00c
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
main
|
||||||
|
|
||||||
@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
## 课程内容
|
## 课程内容
|
||||||
|
|
||||||
+ 第一个程序
|
+ [第一个程序](./hello_world/README.md)
|
||||||
+ 开发环境搭建
|
+ [开发环境搭建](./env/README.md)
|
||||||
+ 基础语法
|
+ 基础语法
|
||||||
+ 基础类型
|
+ 基础类型
|
||||||
+ 变量常量与值
|
+ 变量常量与值
|
||||||
|
|||||||
27
day01/env/README.md
vendored
Normal file
27
day01/env/README.md
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# 环境与安装
|
||||||
|
|
||||||
|
|
||||||
|
## 容器
|
||||||
|
|
||||||
|
安装 [DockerDesktop](https://docs.docker.com/desktop/), 课程里面所有的环境(依赖工具) 都基于 Docker 容器进行开发
|
||||||
|
+ kafka
|
||||||
|
+ mysql
|
||||||
|
+ redis
|
||||||
|
+ ...
|
||||||
|
|
||||||
|
## 开发环境
|
||||||
|
|
||||||
|
Mac/Linux:
|
||||||
|
Windows: 需要 配置容器, 基于DevContaienr来进行开发(Linux 容器, 把你的代码挂进去)
|
||||||
|
|
||||||
|
## 安装Go语言
|
||||||
|
|
||||||
|
[安装Go语言](https://go.dev/)
|
||||||
|
|
||||||
|
## IDE与插件
|
||||||
|
|
||||||
|
+ vscode: [Go 插件](https://marketplace.visualstudio.com/items?itemName=golang.Go)
|
||||||
|
|
||||||
|
|
||||||
|
## 基于vscode 做项目开发
|
||||||
|
|
||||||
45
day01/hello_world/README.md
Normal file
45
day01/hello_world/README.md
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# Hello world程序
|
||||||
|
|
||||||
|
## 编译型语言
|
||||||
|
|
||||||
|
+ Shell/Powershell: 脚本(缺少数据结构, 用于命令组装)
|
||||||
|
+ 动态解释型语言: 写好的代码 -> 解释器 -> 运行结果: python, javascript, php, ruby, lua, perl
|
||||||
|
+ 静态带大运行时语言: 写好的代码 -> 静态编译器 -> 可执行文件(中介产物) -> 大运行时(JVM, .NET) -> 运行结果
|
||||||
|
+ 静态编译型语言: 写好的代码 -> 编译器 -> 可执行文件 -> 运行结果: C, C++, Go, Rust
|
||||||
|
|
||||||
|
|
||||||
|
Go: 静态编译型语言
|
||||||
|
|
||||||
|
## 创建一个hello world程序
|
||||||
|
|
||||||
|
写好的代码 -> 编译器 -> 可执行文件 -> 运行结果
|
||||||
|
|
||||||
|
代码
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
println("Hello, World!")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
解读:
|
||||||
|
+ package: Go源文件开头必须使用 package 声明代码所属包,包是 Go 代码分发的最基本单位。若程序需要运行包名必须为 main。
|
||||||
|
+ import: 用于导入程序依赖的所有的包。此程序依赖于 fmt 包。
|
||||||
|
+ func: 用于定义函数。main 函数是程序的入口,若程序需要运行必须声明 main 函数,main
|
||||||
|
函数无参数也无返回值
|
||||||
|
+ fmt.Println 调用 fmt.Println 函数将参数信息打印到控制台
|
||||||
|
|
||||||
|
编译执行:
|
||||||
|
```bash
|
||||||
|
➜ go20 git:(main) ✗ go build ./day01/hello_world/main.go
|
||||||
|
➜ go20 git:(main) ✗ ./main
|
||||||
|
Hello, World!
|
||||||
|
```
|
||||||
|
|
||||||
|
## 程序入口(main.go)
|
||||||
|
|
||||||
|
main.go: 程序入口 (package main, func main())
|
||||||
|
|
||||||
|
+ 脚步程序: 单main.go 文件, 非工程模式,不依赖任何项目结构(静态编译型语言)
|
||||||
|
+ 工程模式: 多个go 文件, 静态编译型语言
|
||||||
5
day01/hello_world/main.go
Normal file
5
day01/hello_world/main.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
println("Hello, World!")
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user