Golang Multimodule Monorepos

Photo by sera on Unsplash

Intro

Full Multimodule Walkthrough

Working Towards a Multimodule Monorepo

$ tree repo/
repo/
├── client
│ ├── go.mod
│ ├── go.sum
│ └── main.go
├── core
│ ├── go.mod
│ └── go.sum
├── integration
│ ├── go.mod
│ └── go.sum
└── toolset
├── go.mod
├── go.sum
└── main.go

Multimodule Monorepo Aspects

module myvcs.org/repo/clientgo 1.14require (
myvcs.org/repo/core v0.0.0
github.com/stretchr/testify v1.6.1
gopkg.in/yaml.v2 v2.2.8 // indirect
)
replace myvcs.org/repo/core v0.0.0 => ../core
package my-package2import (
// typical import
// github.com/my-organization/repo/module1/my-package1

// slightly shorter vanity import
mysite.org/repo/module1/my-package1
)
...
import cycle not allowed
package github.com/repo/modA
imports github.com/repo/modB/pkgB
imports github.com/repo/modA/pkgA
imports github.com/repo/modB/pkgB

Setting it Up

Full walkthrough for a multimodule repo! See the repo or raw to copy-pasta