文件夹结构:
- myproject
- resolver
- resolver.go
- main.go
go mod init github.com/kaleabbyh/foodrecipie
解析器.go:
package resolvers
import "fmt"
func resolverfunc(){
fmt.Println("resolvers are running")
}
main.go:
package main
import (
"fmt"
"github.com/kaleabbyh/foodrecipie/resolvers"
)
func main(){
resolvers.resolverfunc()
fmt.Println("main is running")
}
我尝试按照上面的详细信息进行操作,但它返回了我
没有必需的模块提供包“github.com/kaleabbyh/foodrecipie/resolvers”
尽管您使用了
package resolvers
,但该包的目录名称是resolver
,因此该包的导入路径(无论其名称如何)不是 ,"github.com/kaleabbyh/foodrecipie/resolvers"
而是"github.com/kaleabbyh/foodrecipie/resolver"
。另请注意,为了能够调用导入包中的函数,需要导出这些函数(即它们必须以大写字母开头)。换句话说;
resolvers.resolverfunc()
不会工作(即使你设法解决导入问题),因为resolverfunc
未导出(即以小写字母开头)。请参阅: https: //go.dev/ref/spec#Exported_identifiers