“This is the 22nd day of my participation in the First Challenge 2022. For details: First Challenge 2022”

preface

In the previous chapter, I had a preliminary understanding of the basic knowledge of Go language, and built the Go environment to write and run Hello, World! What are the common commands of Go? This article will briefly introduce the common commands of Go language

Go Common commands

Go command syntax

The syntax format of the Go command is as follows: Go command parameters. The command examples are as follows:

go run test.go
Copy the code

Where go is a command to manage go run is a command to go test.go file is the parameter value. By running the go run test.go command, the test.go file prints “Hello, World!” Information. You can query the common commands by running the go-h command, which is short for go help command.

Go-h or go helpCopy the code

After executing the go help command, the output is shown below. Common Commands

The command describe
bug Startup error report
Build | build build packages and dependencies clean | clear to delete the object files and the cache files doc package | documents show or symbol of document env | printing Go environmental information fix | repair update package to use the new API FMT | reformat BaoYuan generate | Generate Go files get | add dependencies to the current module and install the install | | to compile and install packages and dependencies list are listed package or module mod maintenance | module run | compile and run the Go program test | test package tool | To run a specified go tool version | go print version information vet | report package there may be a mistakeCopy the code

There is only a brief introduction when we use Go’s help command. If you need more information about the command, use Go Help. For example, to view the details of the run command, all you need to do is run:

go help run
Copy the code

The output result is shown as follows:

version

Syntax: go version Command output: Go version go1.17.7 Windows/AMD64 The following output is displayed:

build

  • The build command matches the source file from a single directory, but also the import path, file system path, or pattern to a known package.
  • Go build [-o output] [build flags] [packages]

bug

  • Action: Bug Opens the default browser and launches a new Bug report. The report includes useful system information.
  • Syntax: Go bug

clean

  • Action: Clean Removes object files from the package source directory. The go command builds most objects in a temporary directory, so Go Clean focuses on object file tools left behind by others or manually calling Go Build.
  • Syntax: go clean [clean flags] [build flags] [packages]

doc

  • What it does: Doc prints the document comment parameters (package, constant, func, type, variable, method, or structure field) associated with the item it identifies, and then a line for each level item summarizes that item (package level declaration for package, method for type, and so on).
  • Flags of syntax: go doc [doc] [package | / package. The symbol [. MethodOrField]]

env

  • Function: Env Prints Go environment information.
  • Go env [-json] [-u] [-w] [var…
Run: go envCopy the code

The execution result is shown as follows:

fix

  • Action: Fix runs a Fix for packages whose import path is named.
  • Go fix [packages]

fmt

  • Effect: Reformats the package source
  • Go FMT [-n] [-x] [packages]

get

  • Get parses its command-line arguments into a package for a particular module version, and the update begins. The mod needs these versions, downloads the source code to the module cache, and then builds and installs the naming.
  • Go get [-d] [-t] [-u] [-v] [build flags] [packages]

install

  • Purpose: Compile and install a package named by the import path.
  • Go install [build flags] [packages]

list

  • What it does: Lists named packages, one per line. The most commonly used flags are -f and -JSON, which control other list flags for each wrapper printed output, recording more specific details.
  • Go list [-f format] [-json] [-m] [list flags] [build flags] [packages]

conclusion

Ok, the above is Go learning 02 Go language common command introduction, thank you for reading, I hope you like, if it is helpful to you, welcome to like collection. If there are shortcomings, welcome comments and corrections. See you next time.

About the author: [Little Ajie] a love tinkering with the program ape, JAVA developers and enthusiasts. Public number [Java full stack architect] maintainer, welcome to pay attention to reading communication.