go - Go 模块:go/types conf.Check 返回错误:无法导入 github.com/xxx/yyy/sub
问题描述
我有一个使用 Go 模块的项目,内容go.mod
是
module github.com/xxx/yyy
然后,我创建了一个子目录log
和一个源文件log.go
,项目结构如下:
yyy
- go.mod
- main.go
- log
- log.go
然后我把代码写在main.go
import (
"github.com/xxx/yyy/log"
"go/ast"
"go/build"
"go/importer"
"go/parser"
"go/token"
"go/types"
)
var fileSet = token.NewFileSet()
func main() {
file, err := parser.ParseFile(fileSet, "main", nil, parser.ParseComments)
conf := types.Config{Importer: importer.Default()}
pkg, err := conf.Check(".", fileSet, []*ast.File{file}, nil)
if err != nil {
log.Log.Fatal(err.Error()) // type error
}
}
然后我成功构建它,但是当我运行它时,它会崩溃并记录could not import github.com/xxx/yyy/log
。错误来自conf.Check
肯定,但为什么它会崩溃?不go/types
支持 go 模块?
解决方案
推荐阅读
- java - 如何在 Java 中计算 BMI 体重和身高是一个数组
- ldap - 如何添加到 openLDAP 用户 objectClass
- android - 将 SwipeMenuRecyclerView 迁移到 AndroidX
- android - LeakCanary DialogFragment 泄漏检测
- swift - Swift 没有取消初始化实例
- vue.js - 选中复选框并在 Vue.js 中显示其相关对象
- vuejs2 - 无法通过axios发帖,尾斜杠发错两个请求
- php - 推送到数组后用ajax传递两个变量
- c++ - 如何使用矢量
> 在 C++ 中? - elasticsearch - Elasticsearch / Logstash:从 geoip 插件获取 ASN 号