Chang ‘an rice is expensive, home is not easy

No matter which dynasty in history, for the vast majority of ordinary people, even if they try their best, chang ‘an is probably impossible to stay. Therefore, in view of this reality, even the great poet Bai Juyi of tang Dynasty sighed: “Chang ‘an is expensive, but it is not easy to live in a big city.” Today, facing the same situation, today’s young people directly choose to lie down, rather than pay the rent for others every day 996, 007 is better than simply lie down: “no marriage, no car, no house”, my youth is my own decision.


Go related commands

1, go build

If it is a common package, no files will be generated after it is executed. If you need to generate files under GOPATH/ PKG, you need to run goinstall. In the main package, an executable file is generated in the current directory after you run gobuild. In the GOPATH/ PKG directory, you need to run Go Install. If you run the go Build command in the main package, an executable file is generated in the current directory. If you want to run the goinstall command in the GOPATH/ PKG directory, run the goinstall command. In the main package, an executable file is generated in the current directory after the gobuild command is executed. In the GOPATH/bin directory, you need to run the Go install file. If you have multiple files in a directory, but only want to compile the specified file, you can add the file name after go build. Note that go Build ignores directories that start with _ or. Go file at the beginning.

Go Build parameter description

-o Specifies the output file name. You can take the path, for example, go build -o a/b/c -i Install the corresponding package, compile + go install -a Updates all the latest packages, but not the standard packages. -n Prints the command to be compiled, but does not execute it. -p n specifies the number of compilations that can be run in parallel, the default being the number of cpus. -race Automatically detects data races when compilations are enabled. -v prints the name of the package we are compiling. -work prints the name of the temporary folder at compile time, and does not delete if it already exists. -x prints the command executed, which is similar to -n. -ccFlags 'arg list' to 5c, 6C, 8C calls -compiler name to specify the appropriate compiler. Gccgo or GCCGOFlags -gccGOFlags 'arg list' passes arguments to gCCGO compiler connection call -gcFlags 'arg list' passes arguments to 5G, 6G, 8g call -installSuffix suffix In order to distinguish it from the default install package, use this prefix to reinstall those dependent packages. -race is already -installsuffix race, This can be verified by using the -n command -ldflags 'flag list' to pass parameters to 5L, 6L, or 8L. The -tags 'tag list' call sets the tags that can be used at compile timeCopy the code

2, go clean

Mainly used for a current source package and associated source package compilation generated files

Go Clean Parameter description

-i Clears associated installation packages and runnable files, that is, the files installed by go install. -n Prints the command to be cleared but does not execute it. It is easy to see how the -r loop works. The -r loop clears the package introduced in import. -x prints the detailed commands to execute, which are actually the execution versions of -n printsCopy the code

3, go FMT

It is mainly used to adopt uniform formatting standards for the code you write.

Go FMT parameter description

-l displays the files to be formatted. -w writes the rewritten content directly to the file, rather than printing the result to standard output. -r adds rewriting rules like "A [b:len (a)] -> a [b:]" to make it easier for us to do batch replacements. -s simplifies the code in the file. -d displays the diff before and after formatting instead of writing to the file. If you don't use this tag, only the first 10 errors on different lines are printed. - CPUprofile supports debugging mode and writes corresponding CPUfile to a specified fileCopy the code

4, go a get

The command is used to obtain the remote code package. The execution of this command is actually divided into two steps: the first step is to download the source package, and the second step is to run go install.

Go get Parameter description

-f only works if you include the -u argument. It does not allow -u to verify that each import has been fetched. This is especially useful for packages that are forked locally. -t also downloads the packages needed to run the test. -u forces the network to update the package and its dependencies. -v displays the commands executedCopy the code

5, go install

The first step is to generate the result file. The second step is to move the compiled result to the GOPATH/ PKG or GOPATH/ PKG or GOPATH/ PKG or GOPATH/bin directory.

6, go to the test

Mainly used to execute unit test files

Go test Parameter description

-bench regexp executes benchmarks, for example, -bench=. -cover enables test coverage. -run regexp runs only the functions that the regexp matches, For example, -run=Array, then execute the function -v that starts with Array to display the test detailsCopy the code

7, go tool

It is used to run the specified Go Tool

Go tool fix. Used to repair the old version of the code to a new version before, such as go1 before the old version of the code into a go1, for example, the API changes go tool vet directory | files used to analyze the current directory if the code is the correct code, For example, if the arguments in the FMT.Printf call are not correct, for example, if the function returns early and there is useless code, etc.Copy the code

8, go doc

It is used to view the contents related to documents

9, the go list

This command is used to view all the current installed packages

summary

In fact, go commands are far more than the ones listed above. They are listed from the frequency of daily use, among which go build, Go clean, Go install and go Get are frequently used. You must master these commands.