I am using sha3
package inside a forked go
project. I am using a special feature that does not exist in that package and I had to download a file from gist
, insert it into the sha3
package and compile it.
Everything is working fine. However, anyone who wants to run my code, they have to get that file and insert it into standard sha3
package first, install the package and run my project. What is the best way that I can include the gist
file and sha3
into my commit, so anyone can just clone and run it? Here is the file path:
workspace-
|_src__
|_github.com
| |_myproject
| |_codes
| |_.git
|_golang.org
|_x
|_crypto
|_sha3
|_custom.go
Since go 1.5, you can put a vendor
folder at the root of your project (workspace/src/github.com/myproject/vendor
). This folder is an import path. When building, go build
will first look for packages inside your vendor folder and if not found, will look inside your $GOPATH
.
You can copy your custom golang.org/x/crypto
package inside your vendor folder and add it to your favorite VCS.
The other solution would be to make a fork of the golang.org/x/crypto repository like github.com/user/mycrypto
and use the go get
command to get the code like this:
go get github.com/user/mycrypto
That being said, VonC is right, it's a good practice to use a dependency manager as it will keep track of what version of libraries you have installed, and it allows better portability.
Have a look at dep
:
dep ensure
.If you don't have go dep installed, type first:
go get -u github.com/golang/dep/cmd/dep
That will vendor your dependency: see "Understanding and using the vendor folder".