Go
DataDome Go Integration build detects and protects against bot activity
This DataDome module is to be used on Go platform.
Compatibility
- Go >= 1.20
Pre-requisites
- The server-side key available in your DataDome dashboard
Installation
The module can be installed through the go get
command:
go get github.com/datadome/module-go-package
Usage
The following example use the Gin framework and the DataDome module as a middleware.
package main
import (
"log"
"net/http"
"github.com/datadome/module-go-package/datadome"
"github.com/gin-gonic/gin"
)
// DataDomeMiddleware verifies requests and return the response from the Protection API
func DataDomeMiddleware() gin.HandlerFunc {
dd := &datadome.DataDomeStruct{
DatadomeServerSideKey: "DATADOME_SERVER_SIDE_KEY",
}
return func(c *gin.Context) {
isBlocked, err := dd.DatadomeProtect(c.Writer, c.Request)
if err != nil {
log.Println("error occured during protection: %v", err)
}
if isBlocked {
c.AbortWithStatus(403)
return
}
c.Next()
}
}
func main() {
router := gin.Default()
router.Use(DataDomeMiddleware())
router.GET("/", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "Hello world"})
return
})
router.Run(":8080")
}
Congrats! You can now see your traffic in your DataDome dashboard.
Configuration
The configuration for the module is done by customizing the DataDomeStruct
with dynamic fields.
Refer to the Settings section below for the full list of possible configuration settings.
Settings
Settings | Description | Required | Default value |
---|---|---|---|
DatadomeServerSideKey | Value of your Server Side Key available in the dashboard . | yes | - |
DataDomeEndpoint | Host of the Protection API. | no | api.datadome.co |
DataDomeTimeout | Timeout in milliseconds, after which the request will be allowed. | no | 150 |
EnableGraphQLSupport | Enable the support of GraphQL requests. | no | false |
EnableReferrerRestoration | Set to true to restore original referrer after a challenge is passed. | no | false |
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. | no | - |
UrlPatternExclusion | Regex to match to exclude requests from being processed with the Protection API. If not defined, all requests will be processed. | no | (?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)$ |
Debug | The debug mode to log additional information. | no | false |
FAQ
How do I restore the Referer
request header after a challenge is passed?
Referer
request header after a challenge is passed?After passing a DataDome challenge on browsers other than Firefox, the referrer value is updated to the current URL which can lead to inconsistent results in website analytics.
Since version 1.3.0
, it is possible to restore the Referer
header to its original value for your backend:
- Contact our support team, they will review your requirements and provide you with the best recommendations.
- Set the boolean value of the
EnableReferrerRestoration
setting totrue
.
Updated 14 days ago