[golang]goコマンドのオプションを確認する

カテゴリ: golang

オプションなしでgoコマンドを実行

プログラムgoをオプションなしで実行すると、コマンドの一覧が表示される

$ go
Go is a tool for managing Go source code.

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

Use "go help [topic]" for more information about that topic.

go versionコマンド

go versionコマンドで、goコンパイラのバージョンが表示されます

$ go version
go version go1.10.1 darwin/amd64

go env

go envで、goのビルドに関係する環境変数を一覧表示できます

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xxx/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/xxx/go"
GORACE=""

go fmt

go fmtコマンドを使うと、goのソースコードを標準コーディング規約に合わせで自動成形されます。自動整形は、カレントディレクトリ以下の*.goファイルに適用されます。

インデントのずれや表記の揺れが解消されるので、初心者のうちは特にこまめに実行すると良いです。

go doc

go docでオンラインマニュアルが表示されます。

以下のコマンドでfmtパッケージの全体概要が表示されます

$ go doc fmt
func Printf(format string, a ...interface{}) (n int, err error)
    Printf formats according to a format specifier and writes to standard
    output. It returns the number of bytes written and any write error
    encountered.
...

以下のようにメソッド名も含めて指定すると、fmt.Printf()メソッドの説明が表示されます

> go fmt.Printf
func Printf(format string, a ...interface{}) (n int, err error)
    Printf formats according to a format specifier and writes to standard
       output. It returns the number of bytes written and any write error
    encountered.

Amazonでおトクに買い物する方法
AmazonチャージでポイントGET


Amazonは買いもの前にAmazonギフト券をチャージしてポイントをゲットしないと損!

こちらもおススメ

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です