<p>--edit: turns out I didn't know what vendoring was. I was really just looking for a way to have my files locally so I didn't have to use "go get" to install them on elastic beanstalk. Turns out I can do what I wanted by building my project...</p>
<p>Then just upload bin/application instead of application.go to AWS and look at that! Dependencies packed into the binary. I spent too much time with scripting languages recently, I forgot about <em>real</em> languages producing a binary file that includes your... includes.</p>
<h1></h1>
<h1>original post</h1>
<p>I wasted the whole weekend trying to figure this out myself and still nothing :(</p>
<h1></h1>
<p>I have GO 1.7.x locally and amazon supports 1.5. I'm using EB so I can't install things via ssh on my instance. I also read about the terrifying way GO fetches things live when you build so if 1 dependency breaks the whole thing comes crashing down. I'd like to avoid that with vendoring, does anyone know how that works and can explain to me how I can package my dependencies with my files for EB?</p>
<h1></h1>
<p>When I google for it, it looks to be as simple as having a vendor directory in your root... but what goes in it? I can't find any explicit examples of it. Also, has the syntax / layout / whatever changed between 1.5 and 1.7? I know the experimental flag for vendoring was removed in 1.7 because it's a standard feature now, but how does it work? Is there something specific for AWS that I need to do? I tried moving the files from my gopath to my project's root/vendor and I got "cannot find package in any of (my gopath, my goroot). Does 1.7 vendoring not work in your project directory like 1.5 & 1.6 vendoring?</p>
<h1></h1>
<p>I don't even know what to ask. I hate configuring stuff. Very lost, help pls!</p>
<hr/>**评论:**<br/><br/>SYS9000: <pre><pre><code>go get -u github.com/aws/aws-sdk-go
cd your-project/
mkdir -p vendor/github.com/aws/aws-sdk-go
cp -r $GOPATH/src/github.com/aws/aws-sdk-go vendor/github.com/aws/aws-sdk-go
</code></pre></pre>Mythiix: <pre><p>And yeah...(after I actually bother to read...) you only need to upload your binary file to your EC instance.</p>
<p>Unless you're going to use a EC instance as a remote build machine, then it doesn't matter what version of Go it supports.</p>
<p>*there are some cases where your OS environment might matter, but by and large, copy over the binary and run it. Good to Go</p></pre>Tomnnn: <pre><p>I'm surprised there were no issues. I made the binary with 1.7.3 and amazon is running 1.5. Though maybe once it's an executable binary that doesn't matter? idk... do you think I'll run into any issues? Since I'm using it as the server I already have most of the functionality I want.</p></pre>Mythiix: <pre><p>When you run <code>go build</code> you are creating a completely stand alone executable binary file. Copy (scp or sftp) the file to your EC2 instance and it will run. The only thing you need to worry about is your build target. If you develop on a Mac and want to build for Linux then you need to set <code>GOOS=linux</code>. </p>
<p>Inside your project run this <code>GOOS=linux go build</code> It will create a binary file that you just copy over to your EC2 Linux server</p>
<p>Similarly you may need to set <code>GOARCH</code> if you want to to build for something like Raspberry PI (ARM) or a an older 32bit system, or your own system isn't 64bit</p>
<p><a href="https://golang.org/doc/install/source#environment" rel="nofollow">https://golang.org/doc/install/source#environment</a>
(Edits typos)</p></pre>Tomnnn: <pre><p>huh, I didn't realize galliumos was 64 bit. Looks like there are a lot of things I didn't think about. Good thing I developed on a platform similar to my target :)</p>
<p>and part of my struggle was running elastic beanstalk instead of regular ec2. if it were ec2 I would have installed the files via ssh... but GO is a compiled language so that is not necessary :D</p></pre>materialdesigner: <pre><p>I use github.com/FiloSottile/gvt</p></pre>dontwantanaccounttt: <pre><p>Use glide or godep. Vendor becomes part of your <code>GOPATH/src</code> when you build, so you'd probably have something like <code>vendor/github.com/aws/aws-sdk-go</code>.</p>
<p>Really, use glide or godep -- you shouldn't manage vendored dependencies by hand.</p></pre>Tomnnn: <pre><p>Thanks! updating original post, 1 moment...</p></pre>Mythiix: <pre><p>I personally like govendor</p>
<p>It make is rather simple to <code>govendor fetch github.com/somepackage</code> which might be newer than my $GOPATH version.</p>
<p>This allows me to test/trial things before updating my main local copy in $GOPATH</p>
<p>Also it's just easy to use, you can mix/match what you vendor easily, with <code>govendor add <package></code></p>
<p>Or just <code>govendor add +external</code> to add all your imports into your /vendor </p></pre>tclineks: <pre><p>I've had good success with govendor even with all the gymanstics around protobuf + grpc.</p></pre>shovelpost: <pre><p>Check out this post where I explain <a href="https://www.reddit.com/r/golang/comments/5b8cct/request_for_code_review_2/d9mn8ao/" rel="nofollow">how to vendor</a> for a specific project case.</p></pre>Tomnnn: <pre><p>Thanks! updating original post, 1 moment</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传