2020-08-07 03:16:35 +00:00
|
|
|
# [Modules](https://github.com/golang/go/wiki/Modules)
|
|
|
|
|
|
|
|
First time:
|
|
|
|
|
2020-08-12 16:04:29 +00:00
|
|
|
```sh
|
2020-08-07 03:16:35 +00:00
|
|
|
go mod init
|
|
|
|
```
|
|
|
|
|
|
|
|
Daily workflow:
|
|
|
|
|
2020-08-12 16:04:29 +00:00
|
|
|
```sh
|
2020-08-07 03:16:35 +00:00
|
|
|
# Update modules
|
2022-08-24 04:29:14 +00:00
|
|
|
go get -d -u ./...
|
2020-08-07 03:16:35 +00:00
|
|
|
|
2022-08-24 04:29:14 +00:00
|
|
|
# Add module with chosen commit or version
|
|
|
|
go get -d public.git.com/path/to/module@version
|
|
|
|
|
|
|
|
# Build and intall binary with latest version
|
|
|
|
go install public.git.com/path/to/module@latest
|
2020-08-07 03:16:35 +00:00
|
|
|
|
|
|
|
# Prune no longer used modules
|
|
|
|
go mod tidy
|
|
|
|
|
2022-08-24 04:29:14 +00:00
|
|
|
# Copy modules to local vendor directory (vendor is not recommend anymore)
|
2020-08-07 03:16:35 +00:00
|
|
|
go mod vendor
|
2022-08-24 04:29:14 +00:00
|
|
|
|
|
|
|
# Why use module
|
|
|
|
go mod why -m public.git.com/path/to/module
|
2020-08-07 03:16:35 +00:00
|
|
|
```
|
|
|
|
|
2020-10-14 07:32:31 +00:00
|
|
|
Update go version:
|
2020-08-12 16:04:29 +00:00
|
|
|
|
|
|
|
```sh
|
2020-10-14 07:32:31 +00:00
|
|
|
go mod edit -go=1.XY
|
|
|
|
```
|
|
|
|
|
2020-08-07 03:16:35 +00:00
|
|
|
In world of corporation, we work with private repository, add to `~/.bashrc`, `~/.zshrc`:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
export GOPRIVATE=private.git.com
|
|
|
|
```
|
2022-08-24 04:29:14 +00:00
|
|
|
|
|
|
|
## Thanks
|
|
|
|
|
|
|
|
- https://encore.dev/guide/go.mod
|