Skip to content

Commit 2f673b4

Browse files
author
王下邀月熊 - WxChevalier
committed
Update 模块化.md
1 parent 2168ca4 commit 2f673b4

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎Go/模块化/模块化.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,36 @@ import "fmt"
99
* It reduces the chance of having overlapping names. This keeps our function names short and succinct
1010
* It organizes code so that its easier to find code you want to reuse.
1111
* It speeds up the compiler by only requiring recompilation of smaller chunks of a program. Although we use the package `fmt`, we don't have to recompile it every time we change our program.
12+
13+
# Go Modules
14+
15+
模块根目录和其子目录的所有包构成模块,在根目录下存在 go.mod 文件,子目录会向着父目录、爷目录一直找到 go.mod
16+
文件。
17+
18+
模块路径指模块根目录的导入路径,也是其他子目录导入路径的前缀。 go.mod
19+
文件第一行定义了模块路径,有了这一行才算作是一个模块。
20+
21+
go.mod
22+
文件接下来的篇幅用来定义当前模块的依赖和依赖版本,也可以排除依赖和替换依赖。
23+
24+
module example.com/m
25+
26+
require (
27+
golang.org/x/text v0.3.0
28+
gopkg.in/yaml.v2 v2.1.0
29+
)
30+
31+
replace (
32+
golang.org/x/text => github.com/golang/text v0.3.0
33+
)
34+
这个文件不用手写,可以用 go mod -init -module example.com/m
35+
生成 go.mod
36+
的第一行
37+
38+
39+
40+
41+
42+
43+
44+

0 commit comments

Comments
 (0)