go mod command

go mod init [module path] 

This command creates a new go.mod file in the current directory. It means a new module is rooted at the current directory.

go mod tidy [...]

This command adds any missing module requirements which are necessary and remove unused ones.

go get [module path]

The module we get from go get command is in the module cache.

workspace and multiple modules management

A workspace is a collection of modules.

go work init [directory of a module]

This command creates a go.work file in the workspace directory. The workspace contains the modules in the  [directory of a module]. Then we can use go run command to run a module in the workspace.

go work use [directory]

This command adds a new module into the go.work file. 

 

posted @ 2022-05-21 15:39  hiccuper-  阅读(33)  评论(0)    收藏  举报