Custom and Remote Packages

In Go, visibility is determined simply by the casing of the first letter of a name.

Exported vs. Unexported

  • Exported (Public): Names starting with a Capital letter are exported. They can be accessed by any package that imports them.
  • Unexported (Private): Names starting with a lowercase letter are private. They can only be accessed within the same package.
package mystrings

func Reverse(s string) string { ... } // Exported
func helper() { ... }                // Private

Importing Custom Packages

To import a package from the same module, use the full path relative to the module root.

Importing Remote Packages

Remote packages (like those on GitHub) are imported using their URL.

import "github.com/wagslane/go-tinytime"

Local Development (replace)

If you are developing two modules locally and want one to depend on the other without publishing to GitHub yet, you can use the replace keyword in go.mod:

replace github.com/user/dep => ../dep