Skip to content

Commit e43af8e

Browse files
committed
refactor: revise code comments
1 parent bbb0d5d commit e43af8e

File tree

13 files changed

+135
-133
lines changed

13 files changed

+135
-133
lines changed

build/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
const (
30-
// ShortVersion 短版本号
30+
// ShortVersion short version number
3131
ShortVersion = "1.7.0"
3232
)
3333

@@ -41,7 +41,7 @@ var (
4141
GitCommit string
4242
)
4343

44-
// Version 生成版本信息
44+
// Version returns the version information.
4545
func Version() string {
4646
var buf strings.Builder
4747
buf.WriteString(ShortVersion)

cli/cli.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var (
2424
goroot string
2525
)
2626

27-
// Run 运行g命令行
27+
// Run executes the g command line interface.
2828
func Run() {
2929
app := cli.NewApp()
3030
app.Name = "g"
@@ -94,7 +94,7 @@ const (
9494
mirrorSep = ","
9595
)
9696

97-
// ghome 返回g根目录
97+
// ghome returns the root directory of g installations.
9898
func ghome() (dir string) {
9999
if experimental := os.Getenv(experimentalEnv); strings.EqualFold(experimental, "true") {
100100
if dir = os.Getenv(homeEnv); dir != "" {
@@ -105,13 +105,13 @@ func ghome() (dir string) {
105105
return filepath.Join(homeDir, ".g")
106106
}
107107

108-
// inuse 返回当前的go版本号
108+
// inuse detects currently active Go version.
109109
func inuse(goroot string) (version string) {
110110
p, _ := os.Readlink(goroot)
111111
return filepath.Base(p)
112112
}
113113

114-
// installed 返回当前的已经安装的go版本号
114+
// installed lists all downloaded Go versions.
115115
func installed() (versions map[string]bool) {
116116
dirs, err := os.ReadDir(versionsDir)
117117
if err != nil {
@@ -143,7 +143,7 @@ const (
143143
jsonMode = 1
144144
)
145145

146-
// render 渲染go版本列表
146+
// render outputs version list in specified format.
147147
func render(mode uint8, installed map[string]bool, items []*version.Version, out io.Writer) {
148148
switch mode {
149149
case jsonMode:
@@ -180,7 +180,7 @@ func render(mode uint8, installed map[string]bool, items []*version.Version, out
180180
}
181181
}
182182

183-
// errstring 返回统一格式的错误信息
183+
// errstring formats error messages with consistent style.
184184
func errstring(err error) string {
185185
if err == nil {
186186
return ""

cli/install.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func install(ctx *cli.Context) (err error) {
4242
return cli.ShowSubcommandHelp(ctx)
4343
}
4444

45-
// 查找版本
45+
// Find matching Go version.
4646
c, err := collector.NewCollector(strings.Split(os.Getenv(mirrorEnv), mirrorSep)...)
4747
if err != nil {
4848
return cli.Exit(errstring(err), 1)
@@ -64,12 +64,12 @@ func install(ctx *cli.Context) (err error) {
6464
vname = v.Name()
6565
targetV := filepath.Join(versionsDir, vname)
6666

67-
// 检查版本是否已经安装
67+
// Check if the version is already installed.
6868
if finfo, err := os.Stat(targetV); err == nil && finfo.IsDir() {
6969
return cli.Exit(fmt.Sprintf("[g] %q version has been installed.", vname), 1)
7070
}
7171

72-
// 查找版本下当前平台的安装包
72+
// Find installation packages for current platform
7373
pkgs, err := v.FindPackages(version.ArchiveKind, runtime.GOOS, runtime.GOARCH)
7474
if err != nil {
7575
return cli.Exit(errstring(err), 1)
@@ -127,7 +127,7 @@ func install(ctx *cli.Context) (err error) {
127127
filename := filepath.Join(downloadsDir, fmt.Sprintf("go%s.%s-%s.%s", vname, runtime.GOOS, runtime.GOARCH, ext))
128128

129129
if _, err = os.Stat(filename); os.IsNotExist(err) {
130-
// 本地不存在安装包,从远程下载并检查校验和。
130+
// Download package remotely and verify checksum.
131131
if _, err = pkg.DownloadWithProgress(filename); err != nil {
132132
return cli.Exit(errstring(err), 1)
133133
}
@@ -142,7 +142,7 @@ func install(ctx *cli.Context) (err error) {
142142

143143
} else {
144144
if !skipChecksum {
145-
// 本地存在安装包,检查校验和。
145+
// Verify checksum for local package.
146146
fmt.Println("Computing checksum with", pkg.Algorithm)
147147
if err = pkg.VerifyChecksum(filename); err != nil {
148148
_ = os.Remove(filename)
@@ -152,14 +152,14 @@ func install(ctx *cli.Context) (err error) {
152152
}
153153
}
154154

155-
// 删除可能存在的历史垃圾文件
155+
// Clean up legacy files.
156156
_ = os.RemoveAll(filepath.Join(versionsDir, "go"))
157157

158-
// 解压安装包
158+
// Extract installation archive.
159159
if err = archiver.Unarchive(filename, versionsDir); err != nil {
160160
return cli.Exit(errstring(err), 1)
161161
}
162-
// 目录重命名
162+
// Rename version directory.
163163
if err = os.Rename(filepath.Join(versionsDir, "go"), targetV); err != nil {
164164
return cli.Exit(errstring(err), 1)
165165
}
@@ -168,7 +168,7 @@ func install(ctx *cli.Context) (err error) {
168168
return nil
169169
}
170170

171-
// 重新建立软链接
171+
// Recreate symbolic link.
172172
_ = os.Remove(goroot)
173173

174174
if err = mkSymlink(targetV, goroot); err != nil {

collector/internal/go_file_item.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func Convert2Versions(items []*GoFileItem) (vers []*version.Version, err error)
142142
Size: pitem.Size,
143143
})
144144
} else if pitem.isSHA256File() {
145-
// 设置校验和及算法
145+
// Set checksum and hashing algorithm.
146146
for _, ppkg := range pkgMap[ver] {
147147
if !strings.HasPrefix(pitem.FileName, ppkg.FileName) {
148148
continue

collector/official/official_collector.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ const (
3737
Name = "official"
3838
)
3939

40-
// Collector 官方站点版本采集器
40+
// Collector collects Go versions from official download page.
4141
type Collector struct {
4242
url string
4343
pURL *stdurl.URL
4444
doc *goquery.Document
4545
}
4646

47-
// NewCollector 返回采集器实例
47+
// NewCollector creates a new collector instance for official Go downloads.
4848
func NewCollector(downloadPageURL string) (*Collector, error) {
4949
if downloadPageURL == "" {
5050
return nil, errs.ErrEmptyURL
@@ -108,12 +108,12 @@ func (c *Collector) findPackages(table *goquery.Selection) (pkgs []*version.Pack
108108
return pkgs
109109
}
110110

111-
// hasUnstableVersions 返回是否包含非稳定版本的布尔值
111+
// hasUnstableVersions checks if unstable versions exist in document.
112112
func (c *Collector) hasUnstableVersions() bool {
113113
return c.doc.Find("#unstable").Length() > 0
114114
}
115115

116-
// StableVersions Return all stable versions
116+
// StableVersions retrieves all stable Go versions from official releases.
117117
func (c *Collector) StableVersions() (items []*version.Version, err error) {
118118
var divs *goquery.Selection
119119
if c.hasUnstableVersions() {
@@ -147,7 +147,7 @@ func (c *Collector) StableVersions() (items []*version.Version, err error) {
147147
return items, nil
148148
}
149149

150-
// UnstableVersions Return all stable versions
150+
// UnstableVersions fetches pre-release and development builds of Go.
151151
func (c *Collector) UnstableVersions() (items []*version.Version, err error) {
152152
c.doc.Find("#unstable").NextUntil("#archive").EachWithBreak(func(i int, div *goquery.Selection) bool {
153153
vname, ok := div.Attr("id")
@@ -174,7 +174,7 @@ func (c *Collector) UnstableVersions() (items []*version.Version, err error) {
174174
return items, nil
175175
}
176176

177-
// ArchivedVersions Return all archived versions
177+
// ArchivedVersions provides historical Go versions no longer supported.
178178
func (c *Collector) ArchivedVersions() (items []*version.Version, err error) {
179179
c.doc.Find("#archive").Find("div.toggle").EachWithBreak(func(i int, div *goquery.Selection) bool {
180180
vname, ok := div.Attr("id")
@@ -201,7 +201,7 @@ func (c *Collector) ArchivedVersions() (items []*version.Version, err error) {
201201
return items, nil
202202
}
203203

204-
// AllVersions 返回所有已知版本
204+
// AllVersions returns all known Go versions including stable/unstable/archived.
205205
func (c *Collector) AllVersions() (items []*version.Version, err error) {
206206
items, err = c.StableVersions()
207207
if err != nil {

pkg/checksum/checksum.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ import (
3030
"github.com/voidint/g/pkg/errs"
3131
)
3232

33-
// Algorithm 校验和算法
33+
// Algorithm checksum algorithm type
3434
type Algorithm string
3535

3636
const (
37-
// SHA256 校验和算法-sha256
37+
// SHA256 algorithm using SHA-256 hash function.
3838
SHA256 Algorithm = "SHA256"
39-
// SHA1 校验和算法-sha1
39+
// SHA1 algorithm using SHA-1 hash function.
4040
SHA1 Algorithm = "SHA1"
4141
)
4242

43-
// VerifyFile 检查目标文件校验和
43+
// VerifyFile validates file integrity against expected checksum.
4444
func VerifyFile(algo Algorithm, expectedChecksum, filename string) (err error) {
4545
f, err := os.Open(filename)
4646
if err != nil {

0 commit comments

Comments
 (0)