本文记录一下Golang中包引用的一种特殊情况:
现在有这么一个项目结构,使用go.mod管理的
package shape
import (
"fmt"
)
func Show() {
fmt.Println("circle")
}
package shape
import (
"fmt"
)
func Show2() {
fmt.Println("fangxing")
}
package main
import (
"fmt"
"test35/shape"
shapeTwo "test35/shape/shapeTwo"
)
func main() {
fmt.Println("hello")
shape.Show()
shapeTwo.Show2()
}
大家注意,fangxing.go中的package名也是shape。
在这种情况下,main.go中要使用fangxing.go中的方法,需要这样引入:
import (
shapeTwo "test35/shape/shapeTwo"
)