douchao1864 2014-11-02 12:57
浏览 73
已采纳

Go + Revel:如何导入自定义包?

I am following tutorial of chat room covered here

I changed it to import a local package instead of using the sample from ravel's github. I changed it into something like this in one of the controllers (refresh.go in the tuts):

import (
    "./../chatroom"
    "github.com/revel/revel"
)

And chatroom was in the right directory:

- app
  - chatroom
    - chatroom.go
  - controllers
    - refresh.go
    - app.go

package chatroom was also initialized already in chatroom.go.

But when running the code, I received this error:

The Go code app/tmp/main.go does not compile: local import "./../chatroom" in non-local package

What am I doing wrong here?

  • 写回答

1条回答 默认 最新

  • dongpangzan6425 2014-11-02 13:26
    关注

    It would be best, following this answer to not use a relative path, but a path from the $GOPATH/src

    In your case, is $GOPAHT/src includes app chatroom, you would use

    import app/chatroom
    

    The OP comments:

    working, but I have to include my app name, something like myapp/app/chatroom,

    That makes sense, if $GOPATH/src contains the folder myapp.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿