Skip to navigation

Go SDK

Detectant

Detectant Go SDK

Detectant is a malware scanning API with support for Go

Scan files for malware from Go services and applications.

Install

go get github.com/Detectant/go-sdk

Set your API key in the environment:

export DETECTANT_API_KEY="your-api-key"

Create a client

import (
"os"
detectant "github.com/Detectant/go-sdk/client"
"github.com/Detectant/go-sdk/option"
)
client := detectant.NewClient(
option.WithAPIKey(os.Getenv("DETECTANT_API_KEY")),
)

Scan one file

file, err := os.Open("./invoice.pdf")
if err != nil {
log.Fatal(err)
}
defer file.Close()
result, err := client.Scan(context.Background(), file)
if err != nil {
log.Fatal(err)
}
fmt.Println(result.Verdict, result.Detections)

The SDK streams from any io.Reader, so large files do not need to be loaded into memory.

Scan a batch

Upload between 1 and 20 files. Results are returned in the same order as the inputs.

batch, err := client.ScanBatch(context.Background(), []io.Reader{invoice, archive})
if err != nil {
log.Fatal(err)
}
for _, item := range batch.Results {
fmt.Println(item.Filename)
}

Requests retry transient failures twice by default. Use request options to configure retry attempts, timeouts, headers, or a custom HTTP client.

Source

The SDK is generated with Fern and maintained at Detectant/go-sdk. Package documentation is available on pkg.go.dev.