Following the instructions from https://golang.org/doc/install
- Download https://golang.org/doc/install?download=go1.13.3.darwin-amd64.pkg
- Run installer
if you don't set a
$GOPATH
, the default path is~/go
Remember to work outside of your
$GOPATH
!
-
initialize a new module
export GO111MODULE=on go mod init
- this will create a
go.mod
file in your current directory.
- this will create a
-
add a new dependency
-
in your
.go
fileimport rsc.io/quote
-
build your code
go build
-
check your
go.mod
file, it will only show thersc.io/quote
module -
check transitive dependencies with
go list -m all
-
-
list versions
go list -m -versions rsc.io/sampler
-
upgrade modules
-
check available update for all modules via
go list -m -u all
-
update one specific package via (will update your dependency in
go.mod
)go get -u golang.org/x/text v0.3.0
-
upgrade all modules
might not be a good idea though!
go get -u
-
-
downgrading
-
use local changes
# assume the local copy of your module is in ../quote go mod edit -replace 'rsc.io/quote=../quote'
-
use remote fork / specific tag
go mod edit -replace 'rsc.io/quote=github.com/myitcv/[email protected]'
-
testing
-
all modules involved in your release (test all modules plus transitive dependencies)
go test -short all
-
test a single module package
go test rsc.io/quote/...
-
Working outside of the
$GOPATH
-
Initialize Go modules inside the project directory
go mod init go mod tidy