无法引用自己的包。

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

Unable to reference my own packages

问题

我已经创建了一个接口和一个结构体,但每次保存我的Go文件时,编译器都会格式化我的import语句,并指示我的结构体未定义。

我对Go完全不熟悉,所以对于某些人来说,这可能很明显。我已经阅读了文档。

这是我的文件结构:
无法引用自己的包。

我如何正确引用我创建的类型?

英文:

I have created an interface as well as a struct, but every time I save my Go file, the compiler is formatting away my import statement and indicating that my struct is undefined.

I'm totally new to Go, so this probably seems obvious to someone. I've read the documentation.

Here's my file structure:
无法引用自己的包。

How do I properly reference a type I've created?

答案1

得分: 2

当名称来自另一个包时,您需要进行限定。请在左侧的文件中尝试使用models.HttpResult

英文:

You have to qualify a name when it's coming from another package. Try models.HttpResult in the file on the left.

huangapple
  • 本文由 发表于 2016年12月16日 08:38:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/41175616.html
匿名

发表评论

匿名网友

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

确定