条件付きコンパイルを構築して行きます

公式情報

PKG / GO /ビルド

ビルドタグ

また、ビルドタグとして知られているビルドの制約は、始まる行コメントで
// +build
そのリストファイルはパッケージに含まれるべき条件
必须在文件的パッケージを声明前面

// +build linux,386 darwin,!cgo
corresponds to the boolean formula:

(linux AND 386) OR (darwin AND (NOT cgo))
A file may have multiple build constraints. The overall constraint is the AND of the individual constraints. That is, the build constraints:

// +build linux darwin
// +build 386
corresponds to the boolean formula:

(linux OR darwin) AND 386
During a particular build, the following words are satisfied:

- the target operating system, as spelled by runtime.GOOS
- the target architecture, as spelled by runtime.GOARCH
- the compiler being used, either "gc" or "gccgo"
- "cgo", if ctxt.CgoEnabled is true
- "go1.1", from Go version 1.1 onward
- "go1.2", from Go version 1.2 onward
- "go1.3", from Go version 1.3 onward
- "go1.4", from Go version 1.4 onward
- "go1.5", from Go version 1.5 onward
- "go1.6", from Go version 1.6 onward
- "go1.7", from Go version 1.7 onward
- "go1.8", from Go version 1.8 onward
- "go1.9", from Go version 1.9 onward
- "go1.10", from Go version 1.10 onward
- "go1.11", from Go version 1.11 onward
- "go1.12", from Go version 1.12 onward
- "go1.13", from Go version 1.13 onward
- any additional words listed in ctxt.BuildTags// go build -tags 'tag list'

ビルドのために検討されてからファイルを保存するには:

// +ビルドは無視します

ファイルの拡張子

If a file's name, after stripping the extension and a possible _test suffix, matches any of the following patterns:

*_GOOS
*_GOARCH
*_GOOS_GOARCH
(example: source_windows_amd64.go) where GOOS and GOARCH represent any known operating system and architecture values respectively, then the file is considered to have an implicit build constraint requiring those terms (in addition to any explicit constraints in the file).
公開された91元の記事 ウォンの賞賛0 ビュー822

おすすめ

転載: blog.csdn.net/weixin_45594127/article/details/104070329