# 使用二进制形式发布go package

This release adds experimental, minimal support for building programs using binary-only packages, packages distributed in binary form without the corresponding source code. This feature is needed in some commercial settings but is not intended to be fully integrated into the rest of the toolchain. For example, tools that assume access to complete source code will not work with such packages, and there are no plans to support such packages in the “go get” command.

Package build 文档中也有相关的介绍：

It is possible to distribute packages in binary form without including the source code used for compiling the package. To do this, the package must be distributed with a source file not excluded by build constraints and containing a "//go:binary-only-package" comment. Like a build constraint, this comment must appear near the top of the file, preceded only by blank lines and other line comments and with a blank line following the comment, to separate it from the package documentation. Unlike build constraints, this comment is only recognized in non-test Go source files.

The minimal source code for a binary-only package is therefore:

> //go:binary-only-package
>
> package mypkg
>

The source code may include additional Go code. That code is never compiled but will be processed by tools like godoc and might be useful as end-user documentation.


package x

import "fmt"

const PI =3.14

var (
X =100
)

func init() {
fmt.Println("x init")
}

func Add(x, y int) int {
return x + y
}

type S struct {
X, Y int
}


//go:binary-only-package

package x

const PI =0.0

var (
X =0
)

func Add(x, y int) int {
return0
}

type S struct {
X, Y int
}


golang binary-only packages 也能搜到一些相关的 教程 ，有人还写了一个样板例子： tcnksm/go-binary-only-package