<p>I have created a github repository containing golang code which builds and installs as you would expect:</p>
<pre><code> go get -d github.com/skx/sos/...
go install github.com/skx/sos/...
</code></pre>
<p>However inside the source-repository there is <em>also</em> a perl-utility which I'd love to be installed into the <code>$GOPATH/bin</code> directory. Is that possible? Via a hook, or some meta-data?</p>
<p>I've tried to search for other examples because I can imagine that people wish to install default configuration-files, etc, but I found nothing obvious..</p>
<hr/>**评论:**<br/><br/>brogrammingsins: <pre><p>As far as I know it's not possible and I would be happy if this doesn't change. go install compiles and creates the binary in GOPATH/bin but it also compiles and creates packages in GOPATH/pkg no need to add hooks or anything else to a well defined command. If you want to install something, you can use a make file or anything else that's used to achieve this.</p>
<p>You can read more about go install here: <a href="https://golang.org/cmd/go/#hdr-Compile_and_install_packages_and_dependencies" rel="nofollow">https://golang.org/cmd/go/#hdr-Compile_and_install_packages_and_dependencies</a></p></pre>chocolate_bread: <pre><p>I appreciate I can write a <code>Makefile</code>, but then it becomes less idiomatic and more of a custom-deployment. I guess that's the way I need to go though.</p></pre>brogrammingsins: <pre><p>go install is not meant to deploy anything. It's meant to compile and put the artifact in a directory.</p>
<p>It's not about being idiomatic or anything else that could facilities the deployment of a Go application. There's also no idiomatic way of deploying a Go application, it's dependencies or other tools related to the said deployment process.</p></pre>chocolate_bread: <pre><p>Sure. I guess I was trying to say that most of the installation-instructions for projects I see are of the form:</p>
<pre><code> go get ...
$GOPATH/bin/foo -arg1 -arg2 .. -argN
</code></pre>
<p>Rather than:</p>
<pre><code> git clone github.com/user/repo
cd repo
make && sudo make install
</code></pre>
<p>The latter case is obviously trivial for copying a binary, perl script, config-file, etc, etc, into <code>/usr/local/{etc bin}</code>. I have the feeling that if I go down that route my project will become just that little bit more annoying to install, but if that's what I have to do then so be it :)</p></pre>brogrammingsins: <pre><p>You need sudo for make install only if you copy something where the user doesn't have access to.</p>
<p>And if your user can copy paste the first option, it can certainly copy paste the second. </p>
<p>Finally, I don't understand the case where you'd need a file, especially a Python one, to run the Go binary. Can you provide the repository you are working on? Or the concrete case for this. Maybe I'm missing something obvious from your need. </p></pre>chocolate_bread: <pre><blockquote>
<p>You need sudo for make install only if you copy something where the user doesn't have access to.</p>
</blockquote>
<p>Indeed, but this is common.</p>
<blockquote>
<p>Finally, I don't understand the case where you'd need a file, especially a Python one, to run the Go binary. Can you provide the repository you are working on? </p>
</blockquote>
<p>The repository was included in the original post, <a href="http://github.com/skx/sos/" rel="nofollow">but here it is again</a>. There's a utility to sync contents between two servers written in Perl - obviously the ideal would be that it was written in golang too, but I've not yet got there.</p>
<p>A more common example would be a binary that wanted to read a configuration file. So when installing source from a tarball you'd generally find that <code>make install</code> dropped a default file in place. (Yes some software can usefully run without a configuration file, just using default settings, but it's not unexpected for some services to demand a valid config file - containing DB credentials & etc).</p></pre>brogrammingsins: <pre><p>Ok, sorry for not checking the repo in the question, I thought it's an example. </p>
<p>And like I've said, go install is NOT for deployment, the sooner you accept this the sooner you can start to move to finding a better solution to distribute your software in binary form. </p>
<p>Which brings me to the last point you make about config files. You ca happily accept default values for an application OR simply os.Exit(1) if you have missing values that are mandatory. 12 factor apps for example recommends running using env variables. </p></pre>HectorJ: <pre><p>In case of a config file, you could make the program write/copy the default file (possibly embedded into the binary via go-bindata) if it does not already exists </p>
<p>For your Perl program:</p>
<ul>
<li><p>if it is used by your Go program, you can try the approach I just described.</p></li>
<li><p>if it is a separated program, I'm afraid you're trying to use <code>go install</code> for something it wasn't made to do.</p></li>
</ul></pre>interactiv_: <pre><p>you shouldn't even try to do that. You should make people install an installer and that installer should be responsible for calling go executable. So if your project is foo you should make people go get foo-installer, then they should run it themselves.</p></pre>raff99: <pre><p>I have been having some strange thought about using go generate to do something similar. But I am afraid of even try it :)</p></pre>wwader: <pre><p>A quite ugly way i guess would be to create small bin wrapper programs in go that execs $GOPATH/src/../../file.pl etc. But yeah... ugly :)</p></pre>natefinch: <pre><p>Many projects have a build.go file that you can run with go run build.go, and it'll do all the right things. Cross platform, unlike perl or makefiles (well, in theory those are cross platform, but you're guaranteed they have go installed if they're running go install ;)</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传