go imported and not used: as, undefined

huangapple go评论66阅读模式
英文:

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

请注意fileFile的不同大小写。由于你提到了重命名文件,我假设你的代码实际上是这样的:

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.

huangapple
  • 本文由 发表于 2016年1月20日 21:22:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/34901259.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定