【从零开始学习Go语言】四.Go常用命令释义

  • 一.go hlep 命令释义
  • 1.1 go env 命令
  • 1.2 go run 命令
  • 1.3 go get 命令
  • 1.4 go build 命令
  • 1.5 go install 命令
  • 1.6 go clean命令
  • 1.7 go test命令
  • 1.8 go list命令



【从零开始学习Go语言】四.Go常用命令释义_golang

一.go hlep 命令释义

如果有玩过linux应该都使用过这个命令 help,而我们的go语言在终端中也有一些好用的工具

执行如下go help 命令可查看关于go命令的帮助

go help

执行成功,显示如下

▶ go help
Go is a tool for managing Go source code.

Usage:

    go <command> [arguments]

The commands are:

    bug         start a bug report
    build       compile packages and dependencies
    clean       remove object files and cached files
    doc         show documentation for package or symbol
    env         print Go environment information
    fix         update packages to use new APIs
    fmt         gofmt (reformat) package sources
    generate    generate Go files by processing source
    get         add dependencies to current module and install them
    install     compile and install packages and dependencies
    list        list packages or modules
    mod         module maintenance
    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:

    buildmode   build modes
    c           calling between Go and C
    cache       build and test caching
    environment environment variables
    filetype    file types
    go.mod      the go.mod file
    gopath      GOPATH environment variable
    gopath-get  legacy GOPATH go get
    goproxy     module proxy protocol
    importpath  import path syntax
    modules     modules, module versions, and more
    module-get  module-aware go get
    module-auth module authentication using go.sum
    module-private module configuration for non-public modules
    packages    package lists and patterns
    testflag    testing flags
    testfunc    testing functions

Use "go help <topic>" for more information about that topic.

这里对其上一些命令作出相关解释:

1.1 go env 命令

go env 命令用于打印Go语言的环境信息

go env

执行成功,如下所示

【从零开始学习Go语言】四.Go常用命令释义_编程语言_02


1.2 go run 命令

go run 命令用于编译并运行命令源码文件,如果你用vim编辑go文件并希望他暂时跑起来查看效果,使用此命令:go run file_name

go run  (记得加上你的go源码文件哦~)

执行成功,如下所示

【从零开始学习Go语言】四.Go常用命令释义_go_03


1.3 go get 命令

go get 命令用于可以根据要求和实际情况从互联网上下载或更新指定的代码包及其依赖包,并对它们进行编译和安装。当需要一些第三方包,比如web框架gin的时候,需要使用此命令来下载,类似python的pip

go get

执行成功,如下图所示

【从零开始学习Go语言】四.Go常用命令释义_golang_04


1.4 go build 命令

go build 命令用于编译我们指定的源码文件或代码包以及它们的依赖包。

go build (记得加上源码文件哦~)

执行成功,如下所示

【从零开始学习Go语言】四.Go常用命令释义_golang_05


执行命令以后,会在其目录下生成的一个Unix可执行文件,如下图所示

【从零开始学习Go语言】四.Go常用命令释义_Go常用命令_06


1.5 go install 命令

go install 命令用于编译并安装指定的代码包及它们的依赖包。这个命令默认安装在GOBIN变量下,如果为空,则安装在GOPATH下,可通过go env查看变量位置

go install

执行成功,如下所示

【从零开始学习Go语言】四.Go常用命令释义_golang_07


1.6 go clean命令

go clean命令用于删除掉执行其它命令时产生的一些文件和目录,通过build编译的文件可直接:go clean清理所有的文件,或者加上-i可清理通过install编译安装的文件

go clean

【从零开始学习Go语言】四.Go常用命令释义_go_08


【从零开始学习Go语言】四.Go常用命令释义_编程语言_09


1.7 go test命令

go test 命令用于对Go语言编写的程序进行测试,对已经编写好的包或程序测试:go test file_name

go test fmt

执行成功,如下所示

【从零开始学习Go语言】四.Go常用命令释义_从零开始学习Go语言_10


1.8 go list命令

Go list 命令用于列出指定的代码包的信息

go list

执行成功,如下所示

【从零开始学习Go语言】四.Go常用命令释义_Go常用命令_11


阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: go