Package management with go vendoring - go

How do you use go vendoring. It is written many places that 1.6 now include vendoring, but I can not find any documentation?
When use go get, I see no vendor folder?
I just need to be able to control packages like npm, apt etc.

As of 1.5 (with a flag) and 1.6 by default the go tools will look in the vendor folder for dependant packages before your GOPATH, for specifics see the design doc
But the go tools do not include tooling to populate that folder for you.
There are many tools that try to handle it for you, for example Godep, gvt and others.
You still need to use go get to get the packages into your GOPATH first.

Related

How to run pkg.go.dev locally as a godoc replacement?

godoc has been removed from the go standard install since 1.12 and looks like it wont be updated anytime soon. pkg.go.dev at least appears to be its successor. It also has additional documentation features like grabbing the README.md file and rendering it in the documentation page.
For these reasons I was hoping to switch over to using pkg.go.dev locally to view and create documentation for small internal packages. The major issue is that unlike godoc there does not seem to be a clear usage guide. I also do not know if pkpg.go.dev is completely overkill for this task. So I would like to know:
Can and should pkg.go.dev be used as a local godoc replacement?
If yes, how would I run it for this task?
Run pkgsite locally.
go install golang.org/x/pkgsite/cmd/pkgsite#latest && pkgsite
References:
https://tip.golang.org/doc/comment
https://pkg.go.dev/golang.org/x/pkgsite/cmd/pkgsite
You can use the x/tools/godoc that has the previous godoc tool
Running godoc [1] on its own worked for me, but was really slow because it generates docs for every single package in the standard library, while I only care about the local package that I am working on. To that end, if your package is in a folder called something, you can move the folder so that it looks like this:
godoc/src/something
Then, go to the godoc folder, and run
godoc -goroot .
Then, browse to localhost:6060. Alternatively, another site is available for
Go docs [2].
https://github.com/golang/tools/tree/master/cmd/godoc
https://godocs.io

Where to find golang modules?

I am from node.js ecosystem.
Golang has released its module system finally and I have read some articles about it:
https://blog.golang.org/using-go-modules
https://github.com/golang/go/wiki/Modules
But, after that, I still didn't find a place like npmjs.com where I can find available go modules.
There is no central repository yet, but note that the module support is still experimental in Go 1.12. It will be enabled by default in Go 1.13 (scheduled for August 2019).
Check out The Go Blog: Go Modules in 2019.
For publicly-available modules, we intend to run a service we call a notary that follows the module index log, downloads new modules, and cryptographically signs statements of the form “module M at version V has file tree hash H.” The notary service will publish all these notarized hashes in a queryable, Certificate Transparency-style tamper-proof log, so that anyone can verify that the notary is behaving correctly. This log will serve as a public, global go.sum file that go get can use to authenticate modules when adding or updating dependencies.
We are aiming to have the go command check notarized hashes for publicly-available modules not already in go.sum starting in Go 1.13.
and
Module Discovery
Finally, we mentioned earlier that the module index will make it easier to build sites like godoc.org. Part of our work in 2019 will be a major revamp of godoc.org to make it more useful for developers who need to discover available modules and then decide whether to rely on a given module or not.
Big Picture
This diagram shows how module source code moves through the design in this post.
There is no central repository for Go modules. As long as you follow the conventions for publishing Go packages (see PackagePublishing), the go tools will be able to fetch your package/module, no matter where you published it.
In order to discover what is already out there in the Go universe, a good starting point is Awesome Go, a curated list of awesome Go packages/modules.
https://search.gocenter.io can be used to search for Go modules, know more about popularity of a module version and even help module authors connect with their consumers. This is GA since end of January 2019 and globally available.
I had the same question. If you start off with the built-in packages (https://golang.org/pkg/), and you follow some non-obvious links, you eventually end up here:
https://pkg.go.dev/

how to upgrade go mod to v2 or higher version?

My go package version is v1.0.7 and now I want to upgrade it to v2.0.0. I create a new tag with it bug when I use go get CODEPATH it still use version v1.0.7. The go.mod should like require CODEPATH v2.0.0+incompatible but I want to know what command will do this?
The document Modules says that add /v2 to module path but didn't tell how to upgrade client's go.mod.
I tried myself and it worked.
Add /v2 to your go.mod's module line module github.com/mnhkahn/aaa/v2;
If you import a sub-package of the module, import like this import "github.com/mnhkahn/aaa/v2/config";
Create a tag with name v2.0.0;
go get github.com/mnhkahn/aaa/v2;
go mod tidy;
The answer from Bryce looks good if you are doing this manually.
If you are interested in an automated approach (for example, perhaps you have many files you would need to visit), a good automated solution is https://github.com/marwan-at-work/mod, which can automatically add, remove, or change the required /vN in your *.go code and your go.mod. See this answer for more details.

Running go mod vendor updates my libraries

I'm trying to vendor my go-modules and am using go 1.11.5. However, when i run go mod vendor, it appears that under the hood go mod tidy is being called first. This updates my go libraries. Unfortunately, I am dependent on an older version of a certain library.
Is there any way I can vendor based on go.sum instead?
Any help much appreciated!
I think the problem I was having is that my go program specified version 1.2.3 of a specific library, but a dependency of my program pulled in version 1.2.4, resulting in a bump when I did a go vendor.
Hostile environment here! I had no idea ;). I will think twice before asking anything in the future.
Peace!

How do I use github packages in go?

Sorry, very much a newbie golang question. I have a github project named journalbeat that I am modifying.
When I clone that repository I can set the GOPATH and run go get to grab all the imports and it places them into src.
I have a new import I want to add.
import "github.com/danwakefield/fnmatch"
but it doesn't grab it. How does simply running go get determine whether something is downloaded or not?
And finally, the vendoring system is used. How do I populate that with the fnmatch? do I create it manually? it all seems very cumbersome.
I thought go get was meant to make all this easy?
Try instead a dependency manager: the most recent and actively developed one is golang/dep.
Reading dep "issue" 943, use:
dep ensure
That will set up vendored dependencies through import analysis, and you can configure locking those down if need be.
Try go get with the verbose flag -v like:
go get -v github.com/danwakefield/fnmatch
This will show you more details. Post the result here.
we use Glide package management tool for GO. Go check it out gitHub link

Resources