mirror of
https://gitee.com/shikong-sk/golang-study
synced 2025-02-22 23:12:15 +08:00
docs: package 包
This commit is contained in:
parent
75fa0bc674
commit
1a00ff6615
13
base/package/calc/calc.go
Normal file
13
base/package/calc/calc.go
Normal 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
3
base/package/go.mod
Normal file
@ -0,0 +1,3 @@
|
||||
module package
|
||||
|
||||
go 1.16
|
14
base/package/main.go
Normal file
14
base/package/main.go
Normal 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))
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user