docs: package 包

This commit is contained in:
Shikong 2021-10-04 03:06:48 +08:00
parent 75fa0bc674
commit 1a00ff6615
3 changed files with 30 additions and 0 deletions

13
base/package/calc/calc.go Normal file
View File

@ -0,0 +1,13 @@
package calc
// 包中的标识符
// 如果首字母为小写 则表示为私有 只在当前包内生效 对外不可见
// 如果为大写 则表示为共有 对外部可见
func Add(x, y int) int {
return x + y
}
func sub(x, y int) int {
return x - y
}

3
base/package/go.mod Normal file
View File

@ -0,0 +1,3 @@
module package
go 1.16

14
base/package/main.go Normal file
View File

@ -0,0 +1,14 @@
package main
import (
"fmt"
// 如果使用 go mod init package 建立主包 则为相对于主包的路径
"package/calc"
// 默认使用相对于 GOPATH/src 下的路径
//"skcks.cn/Shikong/golang-study/base/package/calc"
)
func main() {
fmt.Println(calc.Add(1, 2))
}