This guide will walk you through the process of creating a Go Modules
project, pushing it to Gemfury, and then importing it as a dependency.
Historically, there are a number of ways to create and distribute Go
projects. This guide and our service focuses on Go Modules. And
for simplicity, we will work outside of $GOPATH.
Before you get started, be sure you have the following:
Although we like to use the term “package” at Gemfury to describe
top-level project archives, the Go community prefers the term
“module”. While a “package” in Go is an importable library inside
of a module. So, a single Go module will contain one or more
Go packages.
…
To get started, create a new directory and initialize your module with go mod init
:
$ mkdir gorepo && cd gorepo
$ go mod init git.fury.io/example/gorepo
This command will create an initial go.mod
file to describe your project. The file will contain the project’s name and other module dependencies. Be sure to commit go.mod
and the related go.sum
checksum file into your project’s Git repo.
You may now structure your module as a single root package, and/or multiple packages in a subdirectory structure:
…
Now that you have the structure of your Go module in place, you can push it into your Gemfury account.
Git push
To upload a module to your account, use the Git builder:
# Initial one-time setup
$ git remote add fury https://git.fury.io/USERNAME/gorepo.git
# Push to build a new version
$ git push fury master
Username for 'https://git.fury.io': <Your personal username>
Password for 'https://user@git.fury.io': <Your personal password>
The USERNAME
in the path of your git.fury.io repository URL is the destination of the build, however, the username and password for authentication are your credentials. Usually the former is your team account, and the latter is a personal
one.
…
Go toolkit uses a central proxy to collect a project’s dependencies. By default, it is
configured to the public proxy run by Go’s patron-company (Google).
When you reconfigure your Go tooling to use Gemfury, our blending-proxy will first look
for named packages in your Gemfury account with the fallback to the public proxy for
packages not found there.
Set the following environment variables to configure Go to use Gemfury. This can be done
in your terminal before running go
or in a start-up shell script like $HOME/.profile
:
…