Go中被废弃的特性

io/ioutil包


Go 1.16 将会废弃 io/ioutil 包!

https://go.dev/doc/go1.16

https://makeoptim.com/golang/new-features

  • ioutil.TempDir –> os.MkdirTemp
  • ioutil.WriteFile –> os.WriteFile
  • Discard => io.Discard
  • NopCloser => io.NopCloser
  • ReadAll => io.ReadAll
  • ReadDir => os.ReadDir (注意:返回的是 os.DirEntry 切片而不是 fs.FileInfo 切片)
  • ReadFile => os.ReadFile
  • TempDir => os.MkdirTemp
  • TempFile => os.CreateTemp
  • WriteFile => os.WriteFile

doc.Synopsis包


go/doc(文档)

Synopsis 返回 s 中第一句话的清晰版本。该句在第一个句点后加空格,并且前面没有一个大写字母后结束。结果字符串没有 \n,\r 或 \t 字符,并且在单词之间只使用单个空格。如果 s 从任何非法前缀开始,则结果是空字符串。

n. 提要; (著作、剧本等的)大纲; 概要; 梗概;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Synopsis returns a cleaned version of the first sentence in text.
//
// Deprecated: New programs should use [Package.Synopsis] instead,
// which handles links in text properly.
func Synopsis(text string) string {
var p Package
return p.Synopsis(text)
}


// Synopsis returns a cleaned version of the first sentence in text.
// That sentence ends after the first period followed by space and not
// preceded by exactly one uppercase letter, or at the first paragraph break.
// The result string has no \n, \r, or \t characters and uses only single
// spaces between words. If text starts with any of the IllegalPrefixes,
// the result is the empty string.
func (p *Package) Synopsis(text string) string {
text = firstSentence(text)
lower := strings.ToLower(text)
for _, prefix := range IllegalPrefixes {
if strings.HasPrefix(lower, prefix) {
return ""
}
}
pr := p.Printer()
pr.TextWidth = -1
d := p.Parser().Parse(text)
if len(d.Content) == 0 {
return ""
}
if _, ok := d.Content[0].(*comment.Paragraph); !ok {
return ""
}
d.Content = d.Content[:1] // might be blank lines, code blocks, etc in “first sentence”
return strings.TrimSpace(string(pr.Text(d)))
}

https://github.com/golang/go/issues/51082

https://github.com/golang/proposal/blob/master/design/51082-godocfmt.md


strings.Title