go study notes (3) - go command line

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 functions
Detailed explanation of common command lines in Go

  1. go run command
    1. run command source code file 
    2. Only one command source file and several library source files can be accepted as file parameters 
    3. 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 
    4. ds command - display the directory structure of the specified directory pds command - display the dependencies of the specified code package
    5. Common parameter description
      1. -a: Force compilation of relevant code, regardless of whether their compilation results are up-to-date or not
      2. -n: print commands to run during compilation, but do not actually execute them
      3. -pn: compile in parallel, where n is the number of parallels
      4. -v: list the compiled code package name
      5. -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)
      6. -x: print the commands that need to be run during the compilation process, they will be executed
  2. go install command
    1. Used to compile and install the code package or source code file, the corresponding code package will be compiled first, and then executed
    2. The installed code package will be in pkg/ of the current workspace. . . generate archive file
    3. The installation command source file will generate an executable file in the bin directory or $GOBIN directory of the current workspace
    4. When used without adding any parameters, he will use the current working directory as a code package and install it
  3. go get command
    1. Download and install code packages from remote code repositories
    2. Supported code version control systems are: git, Mercurial, SVN, Bazaar
    3. The specified code package will be downloaded to the src directory of the first workspace included in $GOPATH
    4. go get common parameters
      1. -d: Only perform download operations and do not perform install operations
      2. -fix: perform the corrective action after downloading the code package, and then compile and install it
      3. -u: use the network to update existing code packages and their dependencies
  4. go build command
    1. Used to compile source files or code packages
    2. Compiling non-command source files will not produce any result files, just to check library files etc. will not produce any output
    3. Compiling the command source file will generate an executable file in the command's execution directory
    4. When no parameters are added, it will try to use the current directory as a code package and compile
    5. 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

Guess you like

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