Building and installing your first Go package

Go packages are just a collection of .go files which share the same package directive at the top of each file. You can think of it as a namespace if your from the C++ crowd.

Go provides a couple of makefiles to make it easy to build and install your own Go packages.

Assuming you’ve followed the instructions on their website and have your environment set up correctly, put this makefile in your package directory:

include $(GOROOT)/src/Make.$(GOARCH)

TARG=mypackagename
GOFILES=\
        packagemodule.go\
        anothermodule.go\

include $(GOROOT)/src/Make.pkg

Type
make && make install

and you’re done! You should now have a fully working package that can be imported into other Go projects!

Please note: Go was released yesterday at the time of this posting, it’s likely this process will change sometime in the future.

Leave a Reply