-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8573ed
commit 267a2fb
Showing
2,285 changed files
with
33,265 additions
and
7 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Gobyexample.github.io | ||
|
||
该仓库包含了 [Gobyexample](https://github.com/gobyexample-cn/gobyexample) 生成的静态文件,通过 Github Page 发布至互联网。 | ||
|
||
在线访问地址为:https://gobyexample-cn.github.io | ||
|
||
该仓库仅用于发布内容,不接受 pr。 | ||
|
||
有任意问题,可以前往 [gobyexample](https://github.com/gobyexample-cn/gobyexample),向我们提交 pr 或 issue,我们对此 `非常欢迎` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Gobyexample action | ||
on: | ||
push: | ||
branches: | ||
- master | ||
jobs: | ||
|
||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Set up Go 1.18 | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: 1.18 | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v2 | ||
|
||
- name: Build | ||
run: | | ||
tools/build | ||
cp .github/workflows/README.md ./public | ||
- name: Deploy to gobyexample-cn | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
personal_token: ${{ secrets.PERSONAL_TOKEN }} | ||
external_repository: gobyexample-cn/gobyexample-cn.github.io | ||
publish_branch: master | ||
publish_dir: ./public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.anvil | ||
*.pyc | ||
public/ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gobyexample |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# 期待您的参与 | ||
|
||
例子已完成与[源项目](https://github.com/mmcgrana/gobyexample) master 分支(截止 2022 年 3 月 20 日)的同步,均为 79 个例子。 | ||
|
||
后续如果你发现有更新不及时的情况,或者你觉得目前的翻译内容有任何问题,我们都 `非常欢迎` 各位同学提交 pull request。 | ||
|
||
# 同步进度 | ||
|
||
- [x] Hello World | ||
- [x] Values->值 | ||
- [x] Variables->变量 | ||
- [x] Constants->常量 | ||
- [x] For->For 循环 | ||
- [x] If/Else->If/Else 分支 | ||
- [x] Switch->Switch 分支结构 | ||
- [x] Arrays->数组 | ||
- [x] Slices->切片 | ||
- [x] Maps->Map | ||
- [x] Range->Range 遍历 | ||
- [x] Functions->函数 | ||
- [x] Multiple Return Values->多返回值 | ||
- [x] Variadic Functions->变参函数 | ||
- [x] Closures->闭包 | ||
- [x] Recursion->递归 | ||
- [x] Pointers->指针 | ||
- [x] Strings and Runes->字符串和rune类型 | ||
- [x] Structs->结构体 | ||
- [x] Methods->方法 | ||
- [x] Interfaces->接口 | ||
- [x] Embedding | ||
- [x] Generics->泛型 | ||
- [x] Errors->错误处理 | ||
- [x] Goroutines->协程 | ||
- [x] Channels->通道 | ||
- [x] Channel Buffering->缓冲通道 | ||
- [x] Channel Synchronization->通道同步 | ||
- [x] Channel Directions->通道方向 | ||
- [x] Select->通道选择器 | ||
- [x] Timeouts->超时处理 | ||
- [x] Non-Blocking Channel Operations->非阻塞通道操作 | ||
- [x] Closing Channels->通道的关闭 | ||
- [x] Range over Channels->通道遍历 | ||
- [x] Timers->Timer | ||
- [x] Tickers->Ticker | ||
- [x] Worker Pools->工作池 | ||
- [x] WaitGroups->WaitGroup | ||
- [x] Rate Limiting->速率限制 | ||
- [x] Atomic Counters->原子计数器 | ||
- [x] Mutexes->互斥锁 | ||
- [x] Stateful Goroutines->状态协程 | ||
- [x] Sorting->排序 | ||
- [x] Sorting by Functions->使用函数自定义排序 | ||
- [x] Panic | ||
- [x] Defer | ||
- [x] Recover | ||
- [x] String Functions->字符串函数 | ||
- [x] String Formatting->字符串格式化 | ||
- [x] Text Templates->文本模板 | ||
- [x] Regular Expressions->正则表达式 | ||
- [x] JSON | ||
- [x] XML | ||
- [x] Time->时间 | ||
- [x] Epoch->时间戳 | ||
- [x] Time Formatting / Parsing->时间的格式化和解析 | ||
- [x] Random Numbers->随机数 | ||
- [x] Number Parsing->数字解析 | ||
- [x] URL Parsing->URL 解析 | ||
- [x] SHA256 Hashes->SHA256 散列 | ||
- [x] Base64 Encoding->Base64 编码 | ||
- [x] Reading Files->读文件 | ||
- [x] Writing Files->写文件 | ||
- [x] Line Filters->行过滤器 | ||
- [x] File Paths->文件路径 | ||
- [x] Directories->目录 | ||
- [x] Temporary Files and Directories->临时文件和目录 | ||
- [x] Embed Directive->嵌入的指令 | ||
- [x] Testing and Benchmarking->单元测试和基准测试 | ||
- [x] Command-Line Arguments->命令行参数 | ||
- [x] Command-Line Flags->命令行标志 | ||
- [x] Command-Line Subcommands->命令行子命令 | ||
- [x] Environment Variables->环境变量 | ||
- [x] Logging->日志 | ||
- [x] HTTP Clients->HTTP 客户端 | ||
- [x] HTTP Servers->HTTP 服务端 | ||
- [x] Context | ||
- [x] Spawning Processes->生成进程 | ||
- [x] Exec'ing Processes->执行进程 | ||
- [x] Signals->信号 | ||
- [x] Exit->退出 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
## Go by Example 中文版 | ||
|
||
[Go by Example](https://gobyexample-cn.github.io/) 是一个通过带注释的示例程序学习 Go 语言的网站。网站包含了从简单的 Hello World 到高级特性 Goroutine、Channel 等一系列示例程序,并附带了注释说明,非常适合 Go 语言初学者。 | ||
|
||
如果您想学习 Go 语言基础知识,不要犹豫,请直接前往 [Go by Example](https://gobyexample-cn.github.io/) 开始学习! | ||
|
||
如果您觉得本项目还不错的话,记得回来给个 Star 哦 o(* ̄▽ ̄*)ブ | ||
|
||
## 综述 | ||
|
||
如果你想了解 Go by Example `网站` 是如何构建的,或者想为该项目贡献代码,请查看下面的内容: | ||
|
||
本项目包含了网站的内容和构建工具链,网站使用的是 `public` 目录下静态文件(html 等文件)的内容。它是这样被构建出来的:通过 `程序` 提取 `examples` 目录下的源码及注释,并使用 `templates` 目录下的静态文件模板将其渲染为静态文件,最终将生成的静态文件输出到 `public` 目录下。 | ||
|
||
实现此构建过程的 `程序` 位于 `tools` 目录下,构建得到的 `public` 目录下的静态文件(html 等文件),可以部署到任何支持静态内容的系统。例如 S3、CloudFront 以及任何 Web 服务器。 | ||
|
||
### 构建 | ||
|
||
[![Build Status](https://github.com/mmcgrana/gobyexample/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/mmcgrana/gobyexample/actions) | ||
|
||
若想自行构建该网站,你需要安装 Go。然后运行下面的命令: | ||
|
||
```console | ||
$ tools/build | ||
``` | ||
|
||
若想循环持续构建: | ||
|
||
```console | ||
$ tools/build-loop | ||
``` | ||
|
||
在本地启动服务浏览网站 | ||
|
||
```console | ||
$ tools/serve | ||
``` | ||
|
||
然后再浏览器中打开 `http://127.0.0.1:8000/` | ||
|
||
### 发布 | ||
|
||
下面的例子展示了如何将网站上传至 AWS: | ||
|
||
```console | ||
$ export AWS_ACCESS_KEY_ID=... | ||
$ export AWS_SECRET_ACCESS_KEY=... | ||
$ tools/upload | ||
``` | ||
|
||
## 许可协议 | ||
|
||
该项目的著作权归 Mark McGranaghan 所有,并遵循 [CC BY-SA 3.0](http://creativecommons.org/licenses/by/3.0/) 协议。 | ||
|
||
Go Gopher 的版权归 [Renée French](http://reneefrench.blogspot.com/) 所有,并遵循 [CC BY-SA 3.0](http://creativecommons.org/licenses/by/3.0/) 协议。 | ||
|
||
## 其他语言 | ||
|
||
本项目只是 [mmcgrana](https://github.com/mmcgrana) 的 [Go by Example](https://github.com/mmcgrana/gobyexample) 项目的中文翻译。 | ||
|
||
除中文版外,该项目还有以下语言: | ||
|
||
* [English](https://gobyexample.com) by [mmcgrana/gobyexample](https://github.com/mmcgrana/gobyexample)(原版) | ||
* [Czech](http://gobyexamples.sweb.cz/) by [martinkunc](https://github.com/martinkunc/gobyexample-cz) | ||
* [French](http://le-go-par-l-exemple.keiruaprod.fr) by [keirua](https://github.com/keirua/gobyexample) | ||
* [Italian](http://gobyexample.it) by the [Go Italian community](https://github.com/golangit/gobyexample-it) | ||
* [Japanese](http://spinute.org/go-by-example) by [spinute](https://github.com/spinute) | ||
* [Korean](https://mingrammer.com/gobyexample/) by [mingrammer](https://github.com/mingrammer) | ||
* [Russian](https://gobyexample.com.ru/) by [badkaktus](https://github.com/badkaktus) | ||
* [Spanish](http://goconejemplos.com) by the [Go Mexico community](https://github.com/dabit/gobyexample) | ||
* [Ukrainian](http://butuzov.github.io/gobyexample/) by [butuzov](https://github.com/butuzov/gobyexample) | ||
|
||
## 致谢 | ||
|
||
感谢 [Jeremy Ashkenas](https://github.com/jashkenas) 的 [Docco](http://jashkenas.github.com/docco/),启发了这个项目。 | ||
|
||
## 贡献说明 | ||
|
||
> 从这部分开始,后面的内容都是中文版的贡献者们给自己加的戏。 | ||
> | ||
> 好吧,其实前面的内容也加了很多戏,没有完全根据英文版翻译。 | ||
如果你发现中文版的例子没有及时与英文版同步,或者你觉得某个例子翻译得不够好,甚至只是一个错误的文字、单词或符号,我们都 `非常欢迎` 你能够提交 pull request 以帮助我们使项目更完善,贡献流程大致如下: | ||
|
||
1. Fork 该仓库。 | ||
1. 在 `examples` 目录下找到想要修改的例子,完成修改,这通常是以 `例子`(也就是一个目录)为单位进行修改,当然,你可以一次性修改多个例子。需要注意的是:只修改 `.go` 和 `.sh` 文件。`.hash` 文件是 `tools/build` 自动更新的,主要用于判断文件内容是否有改动; | ||
1. 使用 `tools/build` 命令重新生成静态文件。这一步会格式化代码,并判断内容是否有改动。对于内容有改动的例子,会自动将该例子的代码提交至 `https://play.studygolang.com/` 进行测试。通过测试后,会自动更新静态文件; | ||
1. `tools/serve` 本地预览效果; | ||
1. 通过自测后即可提交 pull request :) | ||
|
||
项目现由 [gobyexample-cn](https://github.com/gobyexample-cn) 维护,例子已完全与英文版同步(截止 2022-3-20),均为 79 个,可以在这里查看 [同步进度](PROGRESS.md)。 | ||
|
||
后续可能会出现与英文版同步不及时的情况,`非常欢迎` 各位同学 fork 并提交 pull request。 | ||
|
||
## 中文版的致谢 | ||
|
||
感谢本翻译项目的原作者 [everyx](https://github.com/everyx),完成了所有文件最初的翻译,同时也感谢项目每一位 [贡献者](https://github.com/gobyexample-cn/gobyexample/graphs/contributors) 的辛勤付出。 | ||
|
||
`JetBrains` 公司为本项目提供了 free JetBrains Open Source license(s),在此表示感谢。 | ||
|
||
[![jetbrains](jetbrains-logo/jetbrains.svg)](https://www.jetbrains.com/?from=gobyexample-cn) | ||
[![jetbrains](jetbrains-logo/goland.svg)](https://www.jetbrains.com/?from=gobyexample-cn) | ||
[![jetbrains](jetbrains-logo/webstorm.svg)](https://www.jetbrains.com/?from=gobyexample-cn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
Hello World | ||
Values->值 | ||
Variables->变量 | ||
Constants->常量 | ||
For->For 循环 | ||
If/Else->If/Else 分支 | ||
Switch->Switch 分支结构 | ||
Arrays->数组 | ||
Slices->切片 | ||
Maps->Map | ||
Range->Range 遍历 | ||
Functions->函数 | ||
Multiple Return Values->多返回值 | ||
Variadic Functions->变参函数 | ||
Closures->闭包 | ||
Recursion->递归 | ||
Pointers->指针 | ||
Strings and Runes->字符串和rune类型 | ||
Structs->结构体 | ||
Methods->方法 | ||
Interfaces->接口 | ||
Embedding | ||
Generics->泛型 | ||
Errors->错误处理 | ||
Goroutines->协程 | ||
Channels->通道 | ||
Channel Buffering->通道缓冲 | ||
Channel Synchronization->通道同步 | ||
Channel Directions->通道方向 | ||
Select->通道选择器 | ||
Timeouts->超时处理 | ||
Non-Blocking Channel Operations->非阻塞通道操作 | ||
Closing Channels->通道的关闭 | ||
Range over Channels->通道遍历 | ||
Timers->Timer | ||
Tickers->Ticker | ||
Worker Pools->工作池 | ||
WaitGroups->WaitGroup | ||
Rate Limiting->速率限制 | ||
Atomic Counters->原子计数器 | ||
Mutexes->互斥锁 | ||
Stateful Goroutines->状态协程 | ||
Sorting->排序 | ||
Sorting by Functions->使用函数自定义排序 | ||
Panic | ||
Defer | ||
Recover | ||
String Functions->字符串函数 | ||
String Formatting->字符串格式化 | ||
Text Templates->文本模板 | ||
Regular Expressions->正则表达式 | ||
JSON | ||
XML | ||
Time->时间 | ||
Epoch->时间戳 | ||
Time Formatting / Parsing->时间的格式化和解析 | ||
Random Numbers->随机数 | ||
Number Parsing->数字解析 | ||
URL Parsing->URL 解析 | ||
SHA256 Hashes->SHA256 散列 | ||
Base64 Encoding->Base64 编码 | ||
Reading Files->读文件 | ||
Writing Files->写文件 | ||
Line Filters->行过滤器 | ||
File Paths->文件路径 | ||
Directories->目录 | ||
Temporary Files and Directories->临时文件和目录 | ||
Embed Directive->嵌入的指令 | ||
Testing and Benchmarking->单元测试和基准测试 | ||
Command-Line Arguments->命令行参数 | ||
Command-Line Flags->命令行标志 | ||
Command-Line Subcommands->命令行子命令 | ||
Environment Variables->环境变量 | ||
Logging->日志 | ||
HTTP Clients->HTTP 客户端 | ||
HTTP Servers->HTTP 服务端 | ||
Context | ||
Spawning Processes->生成进程 | ||
Exec'ing Processes->执行进程 | ||
Signals->信号 | ||
Exit->退出 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 在 Go 中,_数组_ 是一个具有编号且长度固定的元素序列。 | ||
|
||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
|
||
// 这里我们创建了一个刚好可以存放 5 个 `int` 元素的数组 `a`。 | ||
// 元素的类型和长度都是数组类型的一部分。 | ||
// 数组默认值是零值,对于 `int` 数组来说,元素的零值是 `0`。 | ||
var a [5]int | ||
fmt.Println("emp:", a) | ||
|
||
// 我们可以使用 `array[index] = value` 语法来设置数组指定位置的值, | ||
// 或者用 `array[index]` 得到值。 | ||
a[4] = 100 | ||
fmt.Println("set:", a) | ||
fmt.Println("get:", a[4]) | ||
|
||
// 内置函数 `len` 可以返回数组的长度。 | ||
fmt.Println("len:", len(a)) | ||
|
||
// 使用这个语法在一行内声明并初始化一个数组。 | ||
b := [5]int{1, 2, 3, 4, 5} | ||
fmt.Println("dcl:", b) | ||
|
||
// 数组类型是一维的,但是你可以组合构造多维的数据结构。 | ||
var twoD [2][3]int | ||
for i := 0; i < 2; i++ { | ||
for j := 0; j < 3; j++ { | ||
twoD[i][j] = i + j | ||
} | ||
} | ||
fmt.Println("2d: ", twoD) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
a8ce0ee12360e39e9e2bc56a7df7935e845e531b | ||
ZBvk4QydAlR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# 注意,使用 `fmt.Println` 打印数组时,会按照 `[v1 v2 v3 ...]` 的格式打印。 | ||
$ go run arrays.go | ||
emp: [0 0 0 0 0] | ||
set: [0 0 0 0 100] | ||
get: 100 | ||
len: 5 | ||
dcl: [1 2 3 4 5] | ||
2d: [[0 1 2] [1 2 3]] | ||
|
||
# 在 Go 程序中,相较于数组,用得更多的是 _切片(slice)_。我们接着来看切片。 |
Oops, something went wrong.