How to upgrade from v1 to v2
This guide will help you navigate through changes included in version 2 of the Go integration for a successful upgrade.
These changes aim to make the module more consistent and modular by simplifying the client structure, unifying its namespace, improving instantiation with the functional options pattern, and enhancing configuration error handling.
Documentation for version2.x.xPlease refer to the new documentation for detailed instructions on how to use version 2 of the module.
Overview of changes
- Rename
DataDomeStructstructure toClient - Remove
DataDomeprefix on fields of theClientstructure - Replace sub-packages with a single
modulegopackage - Update the
NewClientsignature to use the functional options pattern - Handle configuration errors during the client's instantiation
Migration steps
Step 1: Upgrade to the latest package version
go get github.com/datadome/module-go-package/v2
go mod tidyStep 2: Update your integration
Update the instantiation of the DataDome Client and provide your server-side key in the first parameter of the NewClient function:
dd "github.com/datadome/module-go-package/v2"
func main() {
client, err := dd.NewClient("DATADOME_SERVER_SIDE_KEY")
if err != nil {
// Error may be returned in case of misconfiguration
}
}dd "github.com/datadome/module-go-package"
func main() {
client := &datadome.DataDomeStruct{
DatadomeServerSideKey: "DATADOME_SERVER_SIDE_KEY",
}
}Step 3: Update your configuration
This list describes the optional fields that can be customized:
Option name (v1) | Option name (v2) | Description | Functional option | Default value |
|---|---|---|---|---|
|
| Value of your Server Side Key available in the dashboard . | ||
|
| Host of the Protection API. |
|
|
|
| Timeout in milliseconds, after which the request will be allowed. |
|
|
|
| Enable the support of GraphQL requests. |
|
|
|
| Set to |
|
|
|
| Regex to match to exclude requests from being processed with the Protection API. |
|
|
|
| Regex to match to process the request with the Protection API. If not defined, all requests that don't match |
| |
| The level-based Logger of your choice. |
| The standard log package | |
| REMOVED | The debug mode to log additional information. |
You can find a usage example of the functional options in the snippet below:
client, err := dd.NewClient(
"Some key",
dd.WithEndpoint("api.datadome.co"),
dd.WithTimeout(150),
dd.WithGraphQLSupport(true),
dd.WithReferrerRestoration(true),
dd.WithUrlPatternExclusion(`(?i)\.(avi|flv|mka|mkv|mov|mp4|mpeg|mpg|mp3|flac|ogg|ogm|opus|wav|webm|webp|bmp|gif|ico|jpeg|jpg|png|svg|svgz|swf|eot|otf|ttf|woff|woff2|css|less|js|map|json)$`),
dd.WithUrlPatternInclusion(`(?i)\/included\/endpoint`),
dd.Logger(dd.NewDefaultLogger()),
)Updated 4 days ago
