英文:
go imported and not used: as, undefined
问题
我将文件重命名为File,并将moetemplate重命名为htmlparts,然后执行构建。
./router.go:8: 导入但未使用: "github.com/golangframework/File",将其命名为file
./router.go:11: 导入但未使用: "github.com/golangframework/htmlparts",将其命名为moetemplate
./router.go:21: File.ReadAllBytes中未定义File
./router.go:61: htmlparts.LoadPartFile中未定义htmlparts
./router.go:62: File.ReadAllText中未定义File
./router.go:65: htmlparts.Render中未定义htmlparts
我的导入如下:
package main
import (
"encoding/json"
"log"
"net/http"
"github.com/golangframework/File"
"github.com/golangframework/JSON"
"github.com/golangframework/Object"
"github.com/golangframework/htmlparts"
"github.com/golangframework/httpmongo"
"github.com/golangframework/moeregexp"
)
我还清理了goroot pkg,更新了src,为什么会出现构建错误?
英文:
I renamed file as File,and renamed moetemplate as htmlparts
then go build
./router.go:8: imported and not used: "github.com/golangframework/File" as file
./router.go:11: imported and not used: "github.com/golangframework/htmlparts" as moetemplate
./router.go:21: undefined: File in File.ReadAllBytes
./router.go:61: undefined: htmlparts in htmlparts.LoadPartFile
./router.go:62: undefined: File in File.ReadAllText
./router.go:65: undefined: htmlparts in htmlparts.Render
my import is this
package main
import (
"encoding/json"
"log"
"net/http"
"github.com/golangframework/File"
"github.com/golangframework/JSON"
"github.com/golangframework/Object"
"github.com/golangframework/htmlparts"
"github.com/golangframework/httpmongo"
"github.com/golangframework/moeregexp"
)
and i also cleaned goroot pkg,updated src
why build error?
答案1
得分: 2
请注意file
和File
的不同大小写。由于你提到了重命名文件,我假设你的代码实际上是这样的:
package main
import (
file "github.com/golangframework/File"
)
func main() {
file.ReadAllBytes("foo")
}
要么不要重命名你的File
模块(在导入中删除file
),要么将其引用为file
而不是File
。
英文:
Note the different capitalization of file
and File
. Since you talk about renaming file, I'm assuming that your code really is like
package main
import (
file "github.com/golangframework/File"
)
func main() {
File.ReadAllBytes("foo")
}
Either don't rename your File
module (remove the file
in the import) or refer to it as file
instead of File
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论