Create a local package

Hi every one again. How to create my own a local package into my project, and how to call it?

Hey @RafaelGopher,

You should read through this page:
Particularly this section if this is all you are interested in:

It’s a simple walkthrough for creating your own library.

1 Like

A local package is the same as a package downloaded from a public VCS repository (like github, bitbucket, etc.). It only does not have any VCS underneath.

In particular, you use the same naming conventions, and the path used in the import directive also starts at $GOPATH/src. E.g., import "mycode/mylib" imports the package mylib from $GOPATH/src/mycode/mylib.

However, if you intend to publish your code on GitHub, Bitbucket, Gitlab or elsewhere at some point in the future, you should use the respective import path from the beginning. This saves you from having to rewrite your import paths when you move your pacakge to a go get-able location.

Note that you don’t need to set up, say, a Github repository in order to create a local package at $GOPATH/src/<yourusername>/<yourpackage>. The path, even when named like this, is a local repo until you decide to add a git repo there and sync it to Github.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.