Go study notes (5) Go command tool

The last Go study notes (4) Go automated testing framework

1、go build

This command can be used directly, or it can be used with a code package or source file.

  If it is used directly, it means trying to compile the code package corresponding to the current directory. If the current directory is not a valid code package (included in the $GOPATH/src directory), an error will be reported; if the code package name is included, it means that the compilation is specified. The code package; if you bring the source code file, it means that the specified source code file is compiled.

  The source code files of the GO language are divided into three categories, including command source code files, library source code files, and test source code files. If the command source file or the package containing the command source file (main package) is compiled, an executable file will be generated after the compilation is passed; otherwise, no file will be generated, just a check compilation.

  You can add some flags when executing the go build command, such as:

  -v flag, you can print out the package name (including the package that depends on the compilation process) built during the command execution process. If the go build is a source file, the package name will be printed out command-line-arguments, which is It is the virtual package name generated when compiling the source file, so don't be surprised to see it.

  The -x flag prints all shell commands used during compilation.

  The -o flag is used to specify the path and name of the generated file.

  -a flag to force a recompile.

  -buildmode=shared flag, this parameter can specify the type of result generated by the current compilation, such as static library and dynamic library. The GO language uses static compilation by default. The advantage is that it is very simple to deploy, but the use of dynamic libraries can reduce the size of the distribution package. You can choose according to the actual situation. Note that compilation into a dynamic library is currently not supported under Windows.

  For more parameters, please use go build -h or go help build to view.

 

This command can be used directly, or it can be used with a code package or source file.

  If it is used directly, it means trying to compile the code package corresponding to the current directory. If the current directory is not a valid code package (included in the $GOPATH/src directory), an error will be reported; if the code package name is included, it means that the compilation is specified. The code package; if you bring the source code file, it means that the specified source code file is compiled.

  The source code files of the GO language are divided into three categories, including command source code files, library source code files, and test source code files. If the command source file or the package containing the command source file (main package) is compiled, an executable file will be generated after the compilation is passed; otherwise, no file will be generated, just a check compilation.

  You can add some flags when executing the go build command, such as:

  -v flag, you can print out the package name (including the package that depends on the compilation process) built during the command execution process. If the go build is a source file, the package name will be printed out command-line-arguments, which is It is the virtual package name generated when compiling the source file, so don't be surprised to see it.

  The -x flag prints all shell commands used during compilation.

  The -o flag is used to specify the path and name of the generated file.

  -a flag to force a recompile.

  -buildmode=shared flag, this parameter can specify the type of result generated by the current compilation, such as static library and dynamic library. The GO language uses static compilation by default. The advantage is that it is very simple to deploy, but the use of dynamic libraries can reduce the size of the distribution package. You can choose according to the actual situation. Note that compilation into a dynamic library is currently not supported under Windows.

  For more parameters, please use go build -h or go help build to view.

This command can be used directly, or it can be used with a code package or source file.

  If it is used directly, it means trying to compile the code package corresponding to the current directory. If the current directory is not a valid code package (included in the $GOPATH/src directory), an error will be reported; if the code package name is included, it means that the compilation is specified. The code package; if you bring the source code file, it means that the specified source code file is compiled.

  The source code files of the GO language are divided into three categories, including command source code files, library source code files, and test source code files. If the command source file or the package containing the command source file (main package) is compiled, an executable file will be generated after the compilation is passed; otherwise, no file will be generated, just a check compilation.

  You can add some flags when executing the go build command, such as:

  -v flag, you can print out the package name (including the package that depends on the compilation process) built during the command execution process. If the go build is a source file, the package name will be printed out command-line-arguments, which is It is the virtual package name generated when compiling the source file, so don't be surprised to see it.

  The -x flag prints all shell commands used during compilation.

  The -o flag is used to specify the path and name of the generated file.

  -a flag to force a recompile.

  -buildmode=shared flag, this parameter can specify the type of result generated by the current compilation, such as static library and dynamic library. The GO language uses static compilation by default. The advantage is that it is very simple to deploy, but the use of dynamic libraries can reduce the size of the distribution package. You can choose according to the actual situation. Note that compilation into a dynamic library is currently not supported under Windows.

  For more parameters, please use go build -h or go help build to view.

This command is used for compiling and installing, it can act on main package and non-main package, and then store the compiled executable file in the bin directory of the project, and store the generated archive file (ie static link library) in the pkg of the project Under contents. The usage method is similar to go build, which can be used directly in a code package directory, or can be used by specifying a code package.

2、go clean

This command can delete files and directories generated when other commands are executed

3、go doc

Document comments related, you can build a local GO document server, including your own project comments

4、go env

Used to print the environment information of the GO language, such as GOPATH is the workspace directory, GOROOT is the GO language installation directory, GOBIN is the storage directory of the executable file generated by the go install command (the default is the bin directory of the current workspace), GOEXE is Generate executable file suffix

5、go bug

For GO language debugging

6、go fix

Simply put, this is an automated tool that updates the old grammar in the code package to the new version when the GO language version is upgraded. It's a simple wrapper around go tool fix, which acts on code packages. This method can be used when you need to upgrade your own project or upgrade the downloaded third-party code package. (Download and upgrade the code package can use the go get -fix command)

7、go fmt

Acts on the code package, used to format the code format in the code package, note that the sub-code package in the code package is not included. It is a simple encapsulation of gofmt, equivalent to gofmt -l -w . For more information, please view gofmt -h.

8、go generate

Identify regular commands to run by scanning the Go source code for special comments. It's important to understand that go generate is not part of go build. It does not contain dependency analysis and must be run explicitly before running go build. It is intended to be used by the author of the Go package, not its client.

9、go get

Download the third-party code package and compile and install it. It should be noted that it will be downloaded and installed in the first workspace configured by the GOPATH environment variable.

10、go install

This command is used for compiling and installing, it can act on main package and non-main package, and then store the compiled executable file in the bin directory of the project, and store the generated archive file (ie static link library) in the pkg of the project Under contents. The usage method is similar to go build, which can be used directly in a code package directory, or can be used by specifying a code package.

11、go list

 

To use it directly without any markup is to display the import path of the specified package. For example, go list net/http will display net/http.

  Add the -json flag to this command to display complete information

12、go run

Compile and execute, it can only act on command source files, and is generally used for quick testing in development.

13、go test

A tool for unit testing. The unit test code is recommended to be placed in the same code package as the tested code, with "_test.go" as the later stage, and the test function is recommended to be prefixed with "Test". This command can test the code package, or specify a test code file to run (the tested code file should be brought along with it)

14、go tool

go tool, go tool pprof performance check tool, go tool cgo commands related to C language and GO language

15、go version

print the go version

16、go vet

Static checking tool, generally required for optimization when the project is about to be completed

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325087369&siteId=291194637