我在 $GOPATH/src 中创建了以下文件结构
bitbucket.org/MyName/ProjectName
我这里有以下文件
ProjectName
- controllers/
- meController.go
- app.go
在 app.go 中,我正在这样导入我的 Controller :
import "bitbucket.org/MyName/ProjectName/controllers"
在 main func 中,我尝试使用它的方法。
meController = new(controllers.meController)
m.Get("/", meController.Index)
我的 meController.go 看起来像这样
package controllers
type meController struct {
}
func (controller *meController) Index () string {
return "Hello World"
}
但是我收到了这个错误:
./app.go:5: imported and not used: "bitbucket.org/MyName/ProjectName/controllers"
./app.go:12: undefined: meController
我不知道如何让它工作。
有什么想法吗?
谢谢!
最佳答案
在 Go 中,每个以小写字母开头的符号都不会被包导出。调用你的结构MeController
,你会没事的。
关于go - 不能使用自己包中的结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23702986/