Skip to content

Commit

Permalink
更新标准库
Browse files Browse the repository at this point in the history
  • Loading branch information
before80 committed Jun 5, 2023
1 parent c12c44e commit 33f199b
Show file tree
Hide file tree
Showing 81 changed files with 4,222 additions and 1,994 deletions.
4 changes: 2 additions & 2 deletions content/docs/AQuickGuideToGosAssembler.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ GLOBL runtime·tlsoffset(SB), NOPTR, $4

​ 字段偏移量的形式为 `*type*_*field*`。结构体大小的形式为 `*type*__size`。例如,考虑以下 Go 定义:

```
``` go
type reader struct {
buf [bufSize]byte
r int
Expand Down Expand Up @@ -247,7 +247,7 @@ type reader struct {

​ 列出每个机器的所有指令和其他细节是不切实际的。要查看给定机器(例如ARM)定义了哪些指令,请查看该体系结构的`obj`支持库的源代码,位于目录`src/cmd/internal/obj/arm`中。在该目录中有一个名为`a.out.go`的文件;它包含一长串以`A`开头的常量,如下所示:

```
``` go
const (
AAND = obj.ABaseARM + obj.A_ARCHSPECIFIC + iota
AEOR
Expand Down
18 changes: 9 additions & 9 deletions content/docs/CodeReviewComments.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Most functions that use a Context should accept it as their first parameter:

大多数使用 Context 的函数都应该接受它作为其第一个参数:

```
``` go
func F(ctx context.Context, /* other arguments */) {}
```

Expand Down Expand Up @@ -251,7 +251,7 @@ The import . form can be useful in tests that, due to circular dependencies, can

import .形式在测试中很有用,由于循环依赖关系,不能成为被测试包的一部分。

```
``` go
package foo_test

import (
Expand Down Expand Up @@ -399,7 +399,7 @@ Do not define interfaces before they are used: without a realistic example of us

不要在使用之前就定义接口:如果没有一个真实的使用例子,就很难看出一个接口是否有必要,更不用说它应该包含哪些方法。

```
``` go
package consumer // consumer.go

type Thinger interface { Thing() bool }
Expand All @@ -426,7 +426,7 @@ Instead return a concrete type and let the consumer mock the producer implementa

取而代之的是返回一个具体的类型,让消费者模拟生产者的实现。

```
``` go
package producer

type Thinger struct{ … }
Expand Down Expand Up @@ -469,7 +469,7 @@ Consider what it will look like in godoc. Named result parameters like:

考虑一下在godoc中会是什么样子。命名的结果参数如:

```
``` go
func (n *Node) Parent1() (node *Node) {}
func (n *Node) Parent2() (node *Node, err error) {}
```
Expand All @@ -478,7 +478,7 @@ will be repetitive in godoc; better to use:

在godoc中会有重复,最好使用:

```
``` go
func (n *Node) Parent1() *Node {}
func (n *Node) Parent2() (*Node, error) {}
```
Expand All @@ -487,7 +487,7 @@ On the other hand, if a function returns two or three parameters of the same typ

另一方面,如果一个函数返回两个或三个相同类型的参数,或者一个结果的含义在上下文中并不明确,那么在某些情况下添加名称可能是有用的。不要为了避免在函数中声明一个var而对结果参数进行命名;这样做是以不必要的API的冗长为代价来换取一个小的实现的简洁性。

```
``` go
func (f *Foo) Location() (float64, float64, error)
```

Expand Down Expand Up @@ -515,7 +515,7 @@ A `return` statement without arguments returns the named return values. This is

一个没有参数的返回语句会返回指定的返回值。这就是所谓的 "裸 "返回。

```
``` go
func split(sum int) (x, y int) {
x = sum * 4 / 9
y = sum - x
Expand Down Expand Up @@ -672,7 +672,7 @@ Another common technique to disambiguate failing tests when using a test helper

在使用不同输入的测试助手时,另一个常见的技术是用不同的TestFoo函数来包装每个调用者,从而使测试以该名称失败:

```
``` go
func TestSingleValue(t *testing.T) { testHelper(t, []int{80}) }
func TestNoValues(t *testing.T) { testHelper(t, []int{}) }
```
Expand Down
2 changes: 1 addition & 1 deletion content/docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ fmt.Fprintf(&w, "hello, world\n") // Compile-time error. => 编译时错误。
### Should I define methods on values or pointers? 我应该在值或指针上定义方法?
```
``` go
func (s *MyStruct) pointerMethod() { } // method on pointer
func (s MyStruct) valueMethod() { } // method on value
```
Expand Down
2 changes: 1 addition & 1 deletion content/docs/FAQ_En_Zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ The one exception is that any value, even a pointer to an interface, can be assi

### Should I define methods on values or pointers? 我应该在值或指针上定义方法?

```
``` go
func (s *MyStruct) pointerMethod() { } // method on pointer
func (s MyStruct) valueMethod() { } // method on value
```
Expand Down
2 changes: 1 addition & 1 deletion content/docs/GettingStarted/SettingUpAndUsingGccgo.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ struct __go_slice {

​ Go函数的类型(在这里)是一个指向结构体的指针(这可能会有变化)。结构中的第一个字段指向函数的代码,这将相当于一个指向C函数的指针,其参数类型是相等的,另外还有一个尾随参数。后面的参数是闭包,要传递的参数是指向Go函数结构的指针。当Go函数返回一个以上的值时,C函数返回一个结构。例如,这些函数大致上是等价的:

```
``` go
func GoFunction(int) (int, float64)
struct { int i; float64 f; } CFunction(int, void*)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ a. 使用您的文本编辑器,在`web-service`目录下创建一个名为`mai

b. 在`main.go`文件的顶部,粘贴以下包声明。

```
``` go
package main
```

Expand Down
50 changes: 25 additions & 25 deletions content/docs/GoDocComments.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ The flags are:

​ 类型的文档注释应该解释该类型的每个实例代表或提供什么。如果API很简单,文档注释可以非常简短。例如:

```
``` go
package zip

// A Reader serves content from a ZIP archive.
Expand All @@ -122,7 +122,7 @@ type Reader struct {

​ 默认情况下,程序员应该期望一个类型在同一时间只被一个goroutine使用是安全的。如果类型提供了更强的保证,文档注释中应该说明。例如:

```
``` go
package regexp

// Regexp is the representation of a compiled regular expression.
Expand All @@ -135,7 +135,7 @@ type Regexp struct {

​ Go类型也应该致力于使零值有一个有用的意义。如果不是很明显,就应该把这个意义记录下来。例如:

```
``` go
package bytes

// A Buffer is a variable-sized buffer of bytes with Read and Write methods.
Expand All @@ -147,7 +147,7 @@ type Buffer struct {

​ 对于有导出字段的结构体,文档注释或每个字段的注释应该解释每个导出字段的含义。例如,这个类型的 doc 注释解释了这些字段:

```
``` go
package io

// A LimitedReader reads from R but limits the amount of
Expand All @@ -162,7 +162,7 @@ type LimitedReader struct {

​ 相比之下,这种类型的文档注释将解释留给了每个字段的注释:

```
``` go
package comment

// A Printer is a doc comment printer.
Expand Down Expand Up @@ -196,7 +196,7 @@ A func’s doc comment should explain what the function returns or, for function

​ func 的文档注释应该解释该函数返回什么,或者,对于为副作用而调用的函数,它做了什么。命名的参数或结果可以直接在注释中提及,而不需要任何特殊的语法,如反引号。(这个惯例的后果是,像a这样的名字,可能会被误认为是普通的单词,通常要避免。) 例如:

```
``` go
package strconv

// Quote returns a double-quoted Go string literal representing s.
Expand All @@ -209,7 +209,7 @@ func Quote(s string) string {

和:

```
``` go
package os

// Exit causes the current program to exit with the given status code.
Expand All @@ -226,7 +226,7 @@ If a doc comment needs to explain multiple results, naming the results can make

如果一个文档注释需要解释多个结果,给结果命名可以使文档注释更容易理解,即使这些名字没有在函数的主体中使用。例如

```
``` go
package io

// Copy copies from src to dst until either EOF is reached
Expand Down Expand Up @@ -283,7 +283,7 @@ On the other hand, as noted in the previous section, using an instance of a type

另一方面,正如上一节所指出的,以任何方式使用一个类型的实例,包括调用一个方法,通常都被假定为一次只能使用一个goroutine。如果对并发使用安全的方法没有记录在类型的文档注释中,它们应该被记录在每个方法的注释中。例如:

```
``` go
package sql

// Close returns the connection to the connection pool.
Expand All @@ -300,7 +300,7 @@ Note that func and method doc comments focus on what the operation returns or do

请注意,func和方法的文档注释集中在操作返回或做什么,详细说明调用者需要知道什么。特殊情况下的文档可能特别重要。例如:

```
``` go
package math

// Sqrt returns the square root of x.
Expand All @@ -320,7 +320,7 @@ Doc comments should not explain internal details such as the algorithm used in t

文件注释不应该解释内部细节,如当前实现中使用的算法。这些最好留给函数正文中的注释。当这个细节对调用者特别重要时,给出渐近的时间或空间界限可能是合适的。例如:

```
``` go
package sort

// Sort sorts data in ascending order as determined by the Less method.
Expand All @@ -341,7 +341,7 @@ Go’s declaration syntax allows grouping of declarations, in which case a singl

Go 的声明语法允许对声明进行分组,在这种情况下,一个文档注释可以介绍一组相关的常量,单个常量仅由简短的行末注释记录。例如:

```
``` go
package scanner // import "text/scanner"

// The result of Scan is one of these tokens or a Unicode character.
Expand All @@ -359,7 +359,7 @@ Sometimes the group needs no doc comment at all. For example:

有时该组根本不需要文档注释。例如:

```
``` go
package unicode // import "unicode"

const (
Expand All @@ -374,7 +374,7 @@ On the other hand, ungrouped constants typically warrant a full doc comment star

另一方面,未分组的常数通常需要一个完整的文档注释,以一个完整的句子开始。例如:

```
``` go
package unicode

// Version is the Unicode edition from which the tables are derived.
Expand All @@ -385,7 +385,7 @@ Typed constants are displayed next to the declaration of their type and as a res

类型化的常量被显示在其类型声明的旁边,因此常常省略常量组的文档注释,而选择类型的文档注释。例如:

```
``` go
package syntax

// An Op is a single regular expression operator.
Expand All @@ -411,7 +411,7 @@ The conventions for variables are the same as those for constants. For example,

变量的约定与常量的约定相同。例如,这里有一组分组的变量:

```
``` go
package fs

// Generic file system errors.
Expand All @@ -430,7 +430,7 @@ And a single variable:

还有一个单一的变量:

```
``` go
package unicode

// Scripts is the set of Unicode script tables.
Expand Down Expand Up @@ -458,7 +458,7 @@ Directive comments such as `//go:generate` are not considered part of a doc comm

指令性注释,如//go:generate,不被视为文档注释的一部分,在渲染的文档中被省略。Gofmt 将指令性注释移到文档注释的末尾,前面加一个空行。例如:

```
``` go
package regexp

// An Op is a single regular expression operator.
Expand Down Expand Up @@ -586,7 +586,7 @@ For example:

例如:

```
``` go
package bytes

// ReadFrom reads data from r until EOF and appends it to the buffer, growing
Expand Down Expand Up @@ -628,7 +628,7 @@ For example:

例如:

```
``` go
package url

// PublicSuffixList provides the public suffix of a domain. For example:
Expand Down Expand Up @@ -658,7 +658,7 @@ For example:

例如:

```
``` go
package path

// Clean returns the shortest path name equivalent to path
Expand Down Expand Up @@ -711,7 +711,7 @@ Code blocks often contain Go code. For example:

代码块通常包含Go代码。例如:

```
``` go
package sort

// Search uses binary search...
Expand All @@ -737,7 +737,7 @@ Of course, code blocks also often contain preformatted text besides code. For ex

当然,除了代码之外,代码块还经常包含预格式化的文本。例如:

```
``` go
package path

// Match reports whether name matches the shell pattern.
Expand Down Expand Up @@ -780,7 +780,7 @@ For example, this unindented list has always been interpreted by godoc as a thre

例如,这个没有缩进的列表一直被godoc解释为一个三行的段落,后面是一个单行的代码块:

```
``` go
package http

// cancelTimerBody is an io.ReadCloser that wraps rc with two features:
Expand Down Expand Up @@ -808,7 +808,7 @@ Similarly, the command in this comment is a one-line paragraph followed by a one

类似地,本注释中的命令是一个单行段落,后面是一个单行代码块:

```
``` go
package smtp

// localhostCert is a PEM-encoded TLS cert generated from src/crypto/tls:
Expand Down
2 changes: 1 addition & 1 deletion content/docs/GoTour/Generics/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ draft = false

​ 可以使用类型参数编写 Go 函数,以便对多种类型进行操作。一个函数的类型参数出现在括号中,在函数的参数之前。

```
``` go
func Index[T comparable](s []T, x T) int
```

Expand Down
2 changes: 1 addition & 1 deletion content/docs/Other/ProposalGoBenchmarkDataFormat.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ BenchmarkEncode/text=digits/level=best/size=1e6-8 1 137962041 ns/op

Using sub-benchmarks has benefits beyond this proposal, namely that it would avoid the current repetitive code:

```
``` go
func BenchmarkDecodeDigitsSpeed1e4(b *testing.B) { benchmarkDecode(b, digits, speed, 1e4) }
func BenchmarkDecodeDigitsSpeed1e5(b *testing.B) { benchmarkDecode(b, digits, speed, 1e5) }
func BenchmarkDecodeDigitsSpeed1e6(b *testing.B) { benchmarkDecode(b, digits, speed, 1e6) }
Expand Down
4 changes: 2 additions & 2 deletions content/docs/Other/WeeklySnapshotHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -4352,8 +4352,8 @@ outstanding cgo issues were resolved.

## 2010-12-15

```
Package crypto/cipher has been started, to replace crypto/block.
``` go
package crypto/cipher has been started, to replace crypto/block.
As part of the changes, rc4.Cipher's XORKeyStream method signature has changed from
XORKeyStream(buf []byte)
to
Expand Down

0 comments on commit 33f199b

Please sign in to comment.