dongtanzhu5417 2014-09-29 08:20 采纳率: 100%
浏览 23
已采纳

递归编译文件

I just started with Go, and i love it! I have tried to make the structure of my project a bit more manageable, instead of having everything in my main.go

So now i have a structure like this.

src/
-> main.go
-> routes.go
-> handlers/
--> user_handlers.go

But when i try to build this with the following command

go build -v -o ./bin/my_bin ./src/...

I get this error

cannot use -o with multiple packages

But if i make it a flat structure like this

src/
-> main.go
-> routes.go
-> user_handlers.go

It works just fine, all my files got "package main" in the top of them.

What am i doing wrong?

  • 写回答

2条回答 默认 最新

  • dsarttv037029 2016-03-29 17:08
    关注

    The package name must match the directory name. Moving a source file to a new directory requires that you also change the package name.

    foo/foo.go // package foo
    foo/bar/bar.go // package bar
    foo/bar/qux.go // package bar
    

    The PATH is not relevant in terms of the package name.

    Package foo: /some/path/some/where/foo 
    

    This allows multiple "foo" packages to be created and imported provided your import specifies the desired location of "foo"

    P.S. The convention for package names is lowercase, no punctuation (e.g., no _'s)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB动图的问题
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名