Golang private modules in Bitbucket server
Working with public go modules is quite easy. Private modules, not so much. Private modules + a on-promises service such as Bitbucket server…
I’ve struggled a bit with that precise setup, so I want to share the approach.
First let’s set our assumptions:
- Our bitbucket/stash server is
https://stash.server
- The private module repository lives under project
myproject
and is namedmymodule
. - The ssh url for the repository is
ssh://git@stash.server:2233/myproject/mymodule.git
- The repository has a tag
v0.0.1
- Our Public SSH Key is configured into bitbucket
Configure git to use SSH instead of HTTPs to access our bitbucket server. Please notice the /scm/
segment.
git config --global url."ssh://git@stash.server:9999/".insteadOf "https://stash.server/scm/"
Configure golang to know that modules under stash.server
are private:
# this can be added to .bashrc
export GOPRIVATE=stash.server
#main.go package main
import ( “stash.server/myproject/mymodule )
func main(){ fmt.Printf(“%s”, myModule.Hello()) }
The module can be installed using standard `go get`:
$ go get stash.server/myproject/mymodule@v0.0.1 ```