dqayok7935 2016-04-12 00:34
浏览 89
已采纳

如何安装依赖项的二进制文件?

My Golang project depends on a few packages (i.e. https://github.com/mattes/migrate and https://github.com/joho/godotenv). I know I can go get or go install them separately, but is there a way to install all of the dependencies of a project in one shot? Ideally, I would expect go install ./... to put the migrate and godotenv binaries in my $GOPATH/bin, but it only installs the main package binary and not the binaries of the dependencies.

  • 写回答

1条回答 默认 最新

  • dpiz9879 2016-04-12 11:48
    关注

    Are you asking for a way to install the binaries you want to call, from your local machine, automatically from a go install ./... of your code?

    That isn't going to happen with straight up Go, unless they are listed in the same username or pattern you can type in a single go install command. But just the two listed above are different enough that that can't happen.

    Option 1) Either state to your users to call go install for each Dependency (this is very common).

    Option 2) Or, create a bash/batch file to run them with a simple install.sh command in your repo. Which, would call go install for all of your dependencies. Another more UNIX/C like approach would be to create a Makefile, and tell your users to run make

    Personally, I prefer option 2 as it gives you very complex control over your service or utility. You can start simple; but, later on add tests, go generate commands and whatever else you like in the future - all without having to change your installation instructions just run 'make install' and it will handle it. It also helps with C.I. servers that you can have a make test or anything to your hearts desire; but, different enough that normal users would usually run it. All, within a single Makefile that you can change later.

    I think my Updater script has like 25 go get -u -v commands.

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

报告相同问题?