Skip to content

Instantly share code, notes, and snippets.

@keitaj
Created January 17, 2020 08:39
Show Gist options
  • Save keitaj/cf97ea3d597289a9762810ce9c89b00c to your computer and use it in GitHub Desktop.
Save keitaj/cf97ea3d597289a9762810ce9c89b00c to your computer and use it in GitHub Desktop.
howtogomod

Reference: https://blog.golang.org/using-go-modules

First

Setting

export GOPRIVATE=private.com
export GO111MODULE=on
  • Setting private repository to GOPRIVATE
  • If GO111MODULE=on is set, go.mod and go.sum is updated at go build.

Introduce procedure

$ cd /project
$ go mod init
$ go build
$ go mod vendor

go mod init creates go.mod and go.sum files. go.mod file manages dependency and version for modules. go.sum file manages checksum for dependency modules to confirm reliability.

go mod vendor can take modules to vendor. If vendor is used, execute go mod vendor and set GO111MODULE=off.

Dockerfile

ENV GO111MODULE=off

Setting GO111MODULE=off prevent downloading and use modules from vendor when making a build on docker.

Update modules

$ cd /project
$ go get -u github.com/gorilla/mux
$ go build
$ go mod vendor

Remove unnecessary modules from vendor

$ cd /project
$ go mod tidy
$ go build
$ go mod vendor

go mod tidy and go mod vendor remove unnecessary from vendor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment