Essential Go Packages  Edit on GitHub      File Issue

Creating a package

So you want to create a Go package.

You can use any source code hosting service. For this tutorial let’s assume that you’re using, your account is kjk and you want to create package foo.

Create a repository foo on GitHub.

Create a directory $GOPATH/src/ and checkout repository foo there:

$ mkdir -p $GOPATH/src/
$ cd $GOPATH/src/
$ git clone

Create a file main.go:

package foo

func Bar() string {
    return "bar"

This is a simplest package that defines function Bar.

Notice that package name foo matches directory name foo. It’s not required but recommended.

  ↑ ↓ to navigate     ↵ to select     Esc to close