golang导包
同一个项目下的导包
文件的目录结构
.
├── README.md
├── go.mod
├── main.go
├── mymath
│ ├── multip.go
│ └── sum.go
├── tree.txt
└── utilset
└── hello.go
3 directories, 7 files
/Users/song/codelearn/go_module-master/导包/app/go.mod
module app
go 1.20
/Users/song/codelearn/go_module-master/导包/app/main.go
package main
import (
"app/utilset"
"app/mymath"
"fmt"
)
func main() {
utilset.PrintHello()
sum := mymath.Sum(11,22)
fmt.Println("sum = ",sum)
mul := mymath.Multip(11,22)
fmt.Println("mul = ",mul)
}
/Users/song/codelearn/go_module-master/导包/app/utilset/hello.go
package utilset
import "fmt"
func PrintHello(){
fmt.Println("Hello, 我在 utilset 目录下的 utils 包里")
}
/Users/song/codelearn/go_module-master/导包/app/mymath/multip.go
package mymath
func Multip(a,b int)int{
return a*b
}
/Users/song/codelearn/go_module-master/导包/app/mymath/sum.go
package mymath
func Sum(a,b int)int{
return a+b
}