How to use custom packages

First, be sure to read and understand the “How to write Go code” document.

The actual answer depends on the nature of your “custom package”.

If it’s intended to be of general use, consider employing the so-called “Github code layout”. Basically, you make your library a separate go get-table project.

If your library is for internal use, you could go like this:

  1. Place the directory with library files under the directory of your project.
  2. In the rest of your project, refer to the library using its path relative to the root of your workspace containing the project.

To demonstrate:


Now, in the top-level main.go, you could import "myproject/mylib" and it would work OK.

Leave a Comment