go - 不能使用自己包中的结构

标签 go martini

我在 $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/

相关文章:

go - 如何在 Martini 中设置默认静态页面?

go - 在 golang 中使用容器/ channel 环创建负载均衡器

algorithm - 查找具有相似产品的类别-低效率-转到

go - 从文件访问通过 POST 接收的 JSON

go - Martini 模板和测试

binding - Martini 绑定(bind)似乎不起作用

go - 如何用马提尼输出 CSV?

templates - Golang 模板 : for construction

json - 关于 CPU 缓存或 GC 或任何其他不确定的问题

string - panic :尝试访问字符串元素时,Go中的索引超出范围