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 version 2.x.x

Please refer to the new documentation for detailed instructions on how to use version 2 of the module.

Overview of changes

  • Rename DataDomeStruct structure to Client
  • Remove DataDome prefix on fields of the Client structure
  • Replace sub-packages with a single modulego package
  • Update the NewClient signature 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 tidy

Step 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

DatadomeServerSideKey

  • REMOVED_ (required parameter)

Value of your Server Side Key available in the dashboard .

DataDomeEndpoint

Endpoint

Host of the Protection API.

WithEndpoint

api.datadome.co

DataDomeTimeout

Timeout

Timeout in milliseconds, after which the request will be allowed.

WithTimeout

150

EnableGraphQLSupport

EnableGraphQLSupport

Enable the support of GraphQL requests.

WithGraphQLSupport

false

EnableReferrerRestoration

EnableReferrerRestoration

Set to true to restore original referrer after a challenge is passed.

WithReferrerRestoration

false

UrlPatternExclusion

UrlPatternExclusion

Regex to match to exclude requests from being processed with the Protection API.
If not defined, all requests will be processed.

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)$

UrlPatternInclusion

UrlPatternInclusion

Regex to match to process the request with the Protection API. If not defined, all requests that don't match UrlPatternExclusion will be processed.

WithUrlPatternInclusion

Logger

The level-based Logger of your choice.

WithLogger

The standard log package

Debug

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()),
)