0

我在 $GOPATH/src 中创建了以下文件结构

bitbucket.org/MyName/ProjectName

我这里有以下文件

ProjectName
 - controllers/
    - meController.go
 - app.go

在 app.go 我像这样导入我的控制器:

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

我不知道如何让它工作。

有任何想法吗?

谢谢!

4

1 回答 1

5

在 Go 中,每个以小写字母开头的符号都不会被包导出。打电话给你的结构MeController,你会没事的。

于 2014-05-16T19:18:47.783 回答