top | item 27025462

Go Modules Cheat Sheet

138 points| eandre | 4 years ago |encore.dev

50 comments

order
[+] throwawaygc123|4 years ago|reply
i have also written an article given my frustration in finding simple information on the topic ie. how to upgrade go deps[0] which is not immediately easy to find from the extensive Go wiki[1] and a general go mod how-tos tutorial[2]

[0] https://golang.cafe/blog/how-to-upgrade-golang-dependencies....

[1] https://github.com/golang/go/wiki/Modules#how-to-upgrade-and...

[2] https://www.youtube.com/watch?v=AJxKKmzRTUY

[+] 5dd83f0e|4 years ago|reply
Why did you decide not contributing to the wiki? (curious, not blaming tone)
[+] HumblyTossed|4 years ago|reply
Question: Why is go so integrated(?) with github? I mean, why can't I (or can I?) go get from my own personal gitlab server?
[+] q3k|4 years ago|reply
You can. If you have a `.git` in your import path, it should just work OOTB, using Git as expected. Otherwise, whatever code hosting service has to implement support for returning a proprietary meta tag when serving a ?go-get=1 query - and Gitlab already does that, IIRC.

https://golang.org/cmd/go/#hdr-Remote_import_paths

[+] trianglesphere|4 years ago|reply
All you need to do is have a webpage that has a meta tag with name="go-import" and a content tag with content="URL src-control-method source-control link"

See xyzc.dev/go/ppgen and inspect the source for an example.

[+] whateveracct|4 years ago|reply
I think you can? The urls in package names are just urls. So if you have a url to a git repo, it'll work.
[+] tsimionescu|4 years ago|reply
It isn't, but it is limited to a few source control solutions. If you use something other than Git, Bazaar, SVN, Mercurial, or Fossil, then you're not going to be able to publish Go modules.

Also, Go modules are dependent on DNS, so any domain name change for your repo will have to result in code (import path) changes.

[+] kodablah|4 years ago|reply
I've found explaining multi-module repos w/ go.mod files in subdirs and how that affects using a pseudo-version vs a real version to be the most challenging part. That could be a good addition.
[+] tsimionescu|4 years ago|reply
I'm always surprised just how difficult it is to have Go code in a monorepo given Google's famous use of one. I guess they just don't use modules internally?
[+] whateveracct|4 years ago|reply
I want to be on the new wave of Go modules, but a Nix-managed GOPATH works just as well if not better, especially if you use niv to manage the hashes & versioning.

This is considering the fact that nixpkgs has Go module support.

You can even use Nix's recursive, lazy nature to declare dependencies between libraries too in an equally lighweight way as go mod.

[+] cle|4 years ago|reply
I agree that GOPATH makes integration with other package managers much easier.

However, this is a lost cause at this point. Go is removing GOPATH support in the next release (Go 1.17). See: https://blog.golang.org/go116-module-changes

[+] dilyevsky|4 years ago|reply
Missing go mod download -json for when you want to print the checksums (e.g when adding bazel to external repo)