github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/notes/modules.md (about) 1 ## Go Modules 2 3 ### Adding an external dependency 4 5 > The go command resolves imports by using the specific dependency module 6 > versions listed in go.mod. When it encounters an import of a package not 7 > provided by any module in go.mod, the go command automatically looks up the 8 > module containing that package and adds it to go.mod, using the latest 9 > version. 10 > Source: https://github.com/golang/go/wiki/Modules 11 12 or add a specific version/commit of a dependency 13 14 go get github.com/keybase/go-jsonw@272f108028b0c2328335c35701f2c1ca78ac2320 15 16 ### Updating an external dependency 17 18 go get -u github.com/keybase/go-jsonw 19 20 or to a specific version/commit 21 22 go get -u github.com/keybase/go-jsonw@df90f282c233fcb771aa004d3b8a30caadbc6fb3 23 24 `go get -u` will update the modules subdependencies, remove the `-u` flag if 25 that is not desired. 26 27 ### Removing unused external dependencies 28 29 go mod tidy 30 31 ### Test with a local clone of a dependency 32 33 go mod edit -replace github.com/keybase/go-jsonw=../go-jsonw 34 35 This command modifies the `go.mod` file, be sure to remove it before commiting 36 or merging. 37 38 ### Using a forked dependency 39 40 Forked dependencies can still be referenced by their original name using the Go 41 Modules [`replace` 42 directive](https://github.com/golang/go/wiki/Modules#when-should-i-use-the-replace-directive). 43 Manually edit the bottom of the `go.mod` file under the `keybase maintained forks` section to reference a forked dependency. 44 45 ### Pinning a build tool version 46 47 Required build tools are specified in the `go/buildtools/tools.go` file. You 48 can `go get` a specific version and it will be persistent in the `go/go.mod` 49 file. Running `go install` within the `go/` directory will install 50 the version specified to your `$GOPATH/bin/`.