go command line listing
Enter the "go help" command in Terminal on the installed go machine:
Usage: go command [arguments] The commands are: build compile packages and dependencies clean remove object files and cached files doc show documentation for package or symbol env print Go environment information bug start a bug report fix update packages to use new APIs fmt gofmt (reformat) package sources generate generate Go files by processing source get download and install packages and dependencies install compile and install packages and dependencies list list packages run compile and run Go program test test packages tool run specified go tool version print Go version vet report likely mistakes in packages Use "go help [command]" for more information about a command. Additional help topics: c calling between Go and C buildmode build modes cache build and test caching filetype file types gopath GOPATH environment variable environment environment variables importpath import path syntax packages package lists testflag testing flags testfunc testing functionsDetailed explanation of common command lines in Go
- go run command
- run command source code file
- Only one command source file and several library source files can be accepted as file parameters
- Internal operation steps - first compile the source code file, put the compilation result in a temporary file (including executable file, archive file), and run the compiled result
- ds command - display the directory structure of the specified directory pds command - display the dependencies of the specified code package
- Common parameter description
- -a: Force compilation of relevant code, regardless of whether their compilation results are up-to-date or not
- -n: print commands to run during compilation, but do not actually execute them
- -pn: compile in parallel, where n is the number of parallels
- -v: list the compiled code package name
- -work: Displays the path of the temporary working directory created at compile time, and does not delete it after go run is executed (it will be deleted by default after execution)
- -x: print the commands that need to be run during the compilation process, they will be executed
- go install command
- Used to compile and install the code package or source code file, the corresponding code package will be compiled first, and then executed
- The installed code package will be in pkg/ of the current workspace. . . generate archive file
- The installation command source file will generate an executable file in the bin directory or $GOBIN directory of the current workspace
- When used without adding any parameters, he will use the current working directory as a code package and install it
- go get command
- Download and install code packages from remote code repositories
- Supported code version control systems are: git, Mercurial, SVN, Bazaar
- The specified code package will be downloaded to the src directory of the first workspace included in $GOPATH
- go get common parameters
- -d: Only perform download operations and do not perform install operations
- -fix: perform the corrective action after downloading the code package, and then compile and install it
- -u: use the network to update existing code packages and their dependencies
- go build command
- Used to compile source files or code packages
- Compiling non-command source files will not produce any result files, just to check library files etc. will not produce any output
- Compiling the command source file will generate an executable file in the command's execution directory
- When no parameters are added, it will try to use the current directory as a code package and compile
- All involved code packages will be recompiled when the -a flag is added, and only the archived files that are not the latest code will be compiled when -a is not added.
5. go fmt command
It is used to adjust the format of the code to the standard code style form specified by go. This command is quite a favorite command when copying other people's code, but when the typesetting is confusing in the compiler