til/Development/Go/Modules.md

42 lines
604 B
Markdown
Raw Normal View History

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
go get -u ./...
# Install module with chosen commit or branch
go get public.git.com/module@branch
# Prune no longer used modules
go mod tidy
# Copy modules to local vendor directory
go mod vendor
```
2020-08-12 03:39:49 +00:00
Outside modules:
2020-08-12 16:04:29 +00:00
```sh
2020-08-12 03:39:49 +00:00
GOMODULE11=on go get example.com/foo/bar
```
2020-08-12 16:04:29 +00:00
Update go version in `go.mod`:
```sh
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
```