Go1.7 introduces Binary-Only Packages. This is sample project (named hello
) to create a Binary-Only Pacakage and distribute it as zip
file.
Actual source code is hello.go
in the root directory of this repository. We will not distribute this code.
To create Binary-Only packages, we need prepare 2 files. The one is a special source code file and the other is package binary.
This special source code file is described in doc,
the package must be distributed with a source file not excluded by build constraints and containing a "//go:binary-only-package" comment.
https://tip.golang.org/pkg/go/build/#hdr-Binary_Only_Packages
The example of this source code file is in src/github.com/tcnksm/hello/.
Then, build pacakge binary and place it in pkg/darwin_amd64/github.com/tcnksm/
directory.
$ go build -o pkg/darwin_amd64/github.com/tcnksm/hello.a -x
Finally, zip src
and pkg
directory,
$ zip -r hello.zip src/* pkg/*
Share above zip
file which doesn't have actual source code.
To use this binary pacakge, just unzip it in $GOPATH
,
$ unzip hello.zip -d $GOPATH/