【從零開始學習Go語言】四.Go常用命令釋義


在這裏插入圖片描述

一.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

執行成功,如下所示
在這裏插入圖片描述


1.2 go run 命令

go run 命令用於編譯並運行命令源碼文件,如果你用vim編輯go文件並希望他暫時跑起來查看效果,使用此命令:go run file_name

go run  (記得加上你的go源碼文件哦~)

執行成功,如下所示
在這裏插入圖片描述


1.3 go get 命令

go get 命令用於可以根據要求和實際情況從互聯網上下載或更新指定的代碼包及其依賴包,並對它們進行編譯和安裝。當需要一些第三方包,比如web框架gin的時候,需要使用此命令來下載,類似python的pip

go get 

執行成功,如下圖所示
在這裏插入圖片描述


1.4 go build 命令

go build 命令用於編譯我們指定的源碼文件或代碼包以及它們的依賴包。

go build (記得加上源碼文件哦~)

執行成功,如下所示
在這裏插入圖片描述
執行命令以後,會在其目錄下生成的一個Unix可執行文件,如下圖所示
在這裏插入圖片描述


1.5 go install 命令

go install 命令用於編譯並安裝指定的代碼包及它們的依賴包。這個命令默認安裝在GOBIN變量下,如果爲空,則安裝在GOPATH下,可通過go env查看變量位置

go install 

執行成功,如下所示
在這裏插入圖片描述


1.6 go clean命令

go clean命令用於刪除掉執行其它命令時產生的一些文件和目錄,通過build編譯的文件可直接:go clean清理所有的文件,或者加上-i可清理通過install編譯安裝的文件

go clean

在這裏插入圖片描述
在這裏插入圖片描述


1.7 go test命令

go test 命令用於對Go語言編寫的程序進行測試,對已經編寫好的包或程序測試:go test file_name

go test fmt

執行成功,如下所示
在這裏插入圖片描述


1.8 go list命令

Go list 命令用於列出指定的代碼包的信息

go list 

執行成功,如下所示
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章