简体   繁体   中英

Library dependencies in Go

I've created a library/package in Go and the consensus was that only applications include a vendor folder in their project and libraries don't.

So now I included my package in another ( govendor 'ed) project and everything worked fine, untill it got to Jenkins and it had to use its local resources, where 2 of the dependencies were missing.

My project readme says all you need to do is go get my project and you're done. But that's not the case in case you're using govendoring.

What should be the approach for my library? Can this be solved, or is this 'problem' just something the end-user has to solve because they use govendor ?

This is more of an opinion question I guess, however I'll share what I use.

I use git subtree for vendoring sub repos in my tree then add a //go:generate line to update it later on, for example:

➜ git subtree add --prefix vendor/xxx/yyy/zzz https://github.com/xxx/yyy/zzz master --squash

Then add //go:generate git subtree pull --prefix vendor/xxx/yyy/zzz https://github.com/xxx/yyy/zzz master --squash to one of my library files.

And just run go generate before I make release.

That solves the vendoring issue without the need of any external tools.

Live example: https://github.com/OneOfOne/xxhash/blob/master/xxhash_cgo.go

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM