Skip to content

Commit a7233b7

Browse files
committed
20220404
1 parent 2712ab8 commit a7233b7

File tree

6 files changed

+74
-2
lines changed

6 files changed

+74
-2
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@
2222
/nbdist/
2323
/.nb-gradle/
2424

25-
##
25+
## 忽略包文件,不提交
26+
bin
27+
pkg
28+
src/github.com
29+
src/go-19/module_package/vendor

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ ps:白天上班,晚上更新,尽量日更,比心
5151

5252
[第18章 构建可复用的模块(包)](https://github.com/java-aodeng/golang-examples/blob/master/go-18/client/package_test.go)
5353

54-
第19章 依赖管理
54+
[第19章 依赖管理](https://github.com/java-aodeng/golang-examples/blob/master/go-19/module_package/get_remote_pack_test.go)
5555

5656
第20章 协程机制
5757

go-19/1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
因为 go 编译器默认会在当前目录中查找src目录下package。 果没有src目录,编译器就找不到相应的package
2+
所以使用到包的章节都放在src目录下面了
3+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package module_package
2+
3+
import (
4+
cm "github.com/easierway/concurrent_map"
5+
"testing"
6+
)
7+
8+
//因为 go 编译器默认会在当前目录中查找src目录下package。 果没有src目录,编译器就找不到相应的package
9+
//所以关于包的章节都放在src目录下面了
10+
11+
/*依赖管理
12+
Go未解决的依赖问题
13+
1.同一环境下,不同项目使用同一包的不同版本
14+
2.无法管理对包的特定版本的依赖
15+
16+
vendor路径
17+
随着Go 1.5release版本的发布,vendor目录被添加到除GOPAHR和GOROOT之外的依赖目录查找的解决方案
18+
在Go 1.6之前,你需要手动的设置环境变量
19+
20+
查找依赖包路径的解决方案如下:
21+
1.当前包的vendor目录
22+
2.向上目录查找,直到找到src下的vendor目录
23+
3.GOPATH下面查找依赖包
24+
4.GOROOT下面查找依赖包
25+
26+
常用的依赖管理工具
27+
dodep:https://github.com/tools/godep
28+
glide:https://github.com/Masterminds/glide
29+
dep:https://github.com/golang/dep
30+
31+
window安装glide教程: https://www.cnblogs.com/nickchou/p/8955180.html
32+
安装成功后,我们把src/github.com/easierway包的源文件删除,
33+
在go-19/module_package目录下执行
34+
glide init
35+
glide install
36+
会重新下载包源文件到项目go-19/vendor目录下
37+
38+
遇到的问题:解决go build不去vendor下查找包的问题: https://www.jb51.net/article/202458.htm
39+
问题总结:go 编译器默认会在当前目录中查找src目录下package。如果没有src目录,编译器就找不到相应的package
40+
41+
42+
*/
43+
func TestConcurrentMap(t *testing.T) {
44+
45+
m := cm.CreateConcurrentMap(99)
46+
m.Set(cm.StrKey("key"), 10)
47+
t.Log(m.Get(cm.StrKey("key")))
48+
}
49+
50+
//运行结果
51+
//=== RUN TestConcurrentMap
52+
//--- PASS: TestConcurrentMap (0.00s)
53+
//get_remote_pack_test.go:48: 10 true
54+
//PASS

src/go-19/module_package/glide.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/go-19/module_package/glide.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package: go-19/module_package/get_remote_pack_test.go
2+
import: []
3+
testImport:
4+
- package: github.com/easierway/concurrent_map
5+
version: ^1.0.0

0 commit comments

Comments
 (0)