File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ package client
2
+
3
+ import (
4
+ cm "github.com/easierway/concurrent_map" //还可以导入第三方的包,这是导入一个开源项目的包,会自动git clone到本地
5
+ "series" //这是导入自定义的包 路径,golang-examples\src\series
6
+ "testing"
7
+ )
8
+
9
+ //package(包)
10
+ //1.基本复用模块单元
11
+ //2以首字母大写来表明可被包外代码访问
12
+ //3.代码的package可以和所在目录不一致
13
+ //4.同一目录里的Go代码package要保持一致
14
+ //5.创建包前需要配置项目GOPATH路径 配置教程 https://www.freesion.com/article/4765574656/
15
+ // 注: 配置路径后,我发现go默认是src包下面的,所以项目的包创建在了 golang-examples\src\ 路径下
16
+
17
+ func TestPackage (t * testing.T ) {
18
+ //调用golang-examples\src\series包里面的的Square函数
19
+ t .Log (series .Square (1 ))
20
+
21
+ //t.Log(series.square(1)) 运行结果:undefined: series.square 小写的函数外部不能访问
22
+
23
+ m := cm .CreateConcurrentMap (99 )
24
+ m .Set (cm .StrKey ("key" ), 10 )
25
+ t .Log (m .Get (cm .StrKey ("key" )))
26
+ }
27
+
28
+ //运行结果
29
+ //=== RUN TestPackage
30
+ //--- PASS: TestPackage (0.00s)
31
+ //package_test.go:9: 1
32
+ //PASS
Original file line number Diff line number Diff line change
1
+ package series
2
+
3
+ //自定义的包
4
+
5
+ //首字母小写的函数外部不能调用
6
+ func square (n int ) int {
7
+ return n * n
8
+ }
9
+
10
+ func Square (n int ) int {
11
+ return n * n
12
+ }
You can’t perform that action at this time.
0 commit comments