golang learning - go command

  • go run gofiles... Compile the listed files, generate executable files and execute them. Note that it can only be used for the main package, otherwise there will be an error of go run: cannot run non-main package.

  • go install Compile the package, respectively generate executable files and dependent package files to %GOPATH%/bin, %GOPATH%/pkg

  • go build compiles the package, if it is the main package, it will generate an executable file in the current directory, and other packages will not generate .a files;

  • Go run does not need to set GOPATH, but go build and go install must be set.

  • go run is often used to test some functions, and these codes are generally not included in the final project.

  • go test
    unit test, compile all *_test.go files in the current directory and run the test automatically

  • go test –v

    Unit test, "-v" means that the results will be displayed regardless of whether the use case is passed or not, without "-v" means that only the results of the failed use cases will be displayed

  • go test –bench=".*"
    performance test

  • go test –v –bench=".*"
    to perform unit test and performance test at the same time, same as above

  • go test -run='Test_xxx'
    to test a method

Guess you like

Origin blog.csdn.net/jinniulema/article/details/119102920