
Setting up a Golang project on Bitbucket is a straightforward process, but there are some best practices to keep in mind.
First, you'll need to create a new repository on Bitbucket. This involves clicking the "Create a new repository" button on the Bitbucket dashboard and following the prompts to set up your repository.
Once your repository is created, you can clone it to your local machine using the Bitbucket CLI or by downloading a zip file of the repository.
To get started with a Golang project, you'll need to initialize a new Go module in your repository using the `go mod init` command. This command creates a `go.mod` file in the root of your project that lists the dependencies required by your project.
Bitbucket allows you to manage multiple repositories from a single account, making it easy to collaborate with team members.
See what others are reading: Create a Package in Golang
Setting Up Pipelines
Setting up Pipelines is a crucial step in getting your GoLang project up and running on Bitbucket.
First, you'll need to add a bitbucket-pipelines.yml file to your repository. This file is where you define the build and test process for your project.
The bitbucket-pipelines.yml file is very simplistic and just pulls in your dependencies, runs the tests, and tries to build everything. You can extend this with automatic deployments and other cool stuff later if you want.
Commit the changes and if Pipelines are enabled on your repository, you'll see the build status under Pipelines in the menu or in your commit overview.
If all goes well, you'll see a build status like "This is just a very basic way of building and testing your gb project using Bitbucket Pipelines."
A unique perspective: Golang Status
Golang and Bitbucket
Golang and Bitbucket is a great combination, but you may encounter some challenges, especially when it comes to setting up Continuous Integration (CI) with Bitbucket Pipelines. Fortunately, you can use Docker images to overcome this issue.
Using Docker images with Pipelines makes things easier, but you'll need a Docker image with both Go and gb installed. If you're not comfortable building your own Docker image, you can use a pre-built one, but be aware that it may not be maintained.
You might like: Golang Use Cases
You can set up Pipelines with the most basic Docker knowledge, but if you're short on time, you can use a pre-built image.
To use a private Git repository with Go, you'll need to set the GOPRIVATE environment variable. This variable contains a list of module path prefixes that are considered private, so Go won't use a proxy or try to validate checksums from a public database.
Here are some examples of how to set GOPRIVATE:
- Set a single value: `GOPRIVATE=github.com/matijakrajnik`
- Use a glob pattern to match all repositories: `GOPRIVATE=github.com/matijakrajnik/*`
- Use a comma-separated list to include multiple values: `GOPRIVATE=github.com/matijakrajnik,bitbucket.org/matijakrajnik`
After setting GOPRIVATE, you'll need to configure Git to use SSH instead of HTTPS. This will allow you to authenticate with your private repository using your SSH keys.
Here are the commands to configure Git for GitHub and Bitbucket:
- For GitHub: `git config --global url."https://github.com/".insteadOf [email protected]:`
- For Bitbucket: `git config --global url."https://bitbucket.org/".insteadOf [email protected]:`
Golang Libraries and Tools
You can create a Golang library and put it in Bitbucket to use across your organisation.
To create a Golang project, use the following structure, which makes your project a module to be used in any other app.
In this tutorial, we'll be using Golang version 1.14.
To set up a private Bitbucket Golang library in any project, export the GOPRIVATE variable with the following format: "bitbucket.org/projectname1,bitbucket.org/projectname1".
This allows you to successfully run go get for your private repository.
Additional reading: Golang Create File
Featured Images: pexels.com


