contribute/backend/manage-go-module.md
Create a new module when:
The code has a distinct responsibility or domain
The code needs its own dependency management
The code might be used independently of Grafana
The code has complex dependencies that should be isolated
The code needs to be versioned independently
Initialize the module:
cd pkg/your/new/module
go mod init github.com/grafana/grafana/pkg/your/new/module
make update-workspace
Add module reference to go.work file
Update module consumers If other modules depend on the new module you are introducing, you migh need to temporarily add a replace directive to these consumer modules, while the newly introduced module is not published / in the main branch. You can add a replace directive like this:
// In your module's go.mod
replace github.com/grafana/grafana/pkg/<my-module> => ../../../<my-module>
Dockerfile to include the new module
Example:# Dockerfile
COPY pkg/your/new/module ./pkg/your/new/module
dependabot.yml for dependency updatesExample:
# .github/dependabot.yml
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'daily'
- package-ecosystem: 'gomod'
directories:
- '/'
- '/pkg/your/new/module' # Add your new module here
[!IMPORTANT]
When running the command above, you may notice there will be some invalid revision version errors. This is because the module doesn't exist in the main branch yet and the root go.mod can't find a reference to the new module yet.
make update-workspace againgo.mod