Add a Go Module¶
The repository contains a few submodules. To add a new one and ensure it is tested, follow the following steps:
-
Create a directory for the module:
cd ~/my_path_to/datadog-agent && mkdir mymodule
-
Initialize a new Go module:
cd path/to/mymodule && go mod init
-
Create a dummy root package file
doc.go
:cat >doc.go <<EOL // Unless explicitly stated otherwise all files in this repository are licensed // under the Apache License Version 2.0. // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016-present Datadog, Inc. package mymodule EOL
-
Udpate the
modules.yml
file at the root of the repository with this content:path/to/mymodule: independent: true should_tag: false test_targets: - .
independent
: Should it be importable as an independent module?should_tag
: Should the Agent pipeline tag it?test_targets
: Shouldgo test
target specific subfolders?
-
If you use your module in another module within
datadog-agent
, add therequire
andreplace
directives ingo.mod
.From the other module root, install the dependency with
go get
:Then add the replace directive in thego get github.com/DataDog/datadog-agent/path/to/mymodule
go.mod
file:Example PR: #17350module github.com/DataDog/datadog-agent/myothermodule go 1.18 // Replace with local version replace github.com/DataDog/datadog-agent/path/to/mymodule => ../path/to/mymodule require ( github.com/DataDog/datadog-agent/path/to/mymodule v0.0.0-20230526143644-ed785d3a20d5 )