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

1import (
2 "os"
3
4 detectant "github.com/Detectant/go-sdk/client"
5 "github.com/Detectant/go-sdk/option"
6)
7
8client := detectant.NewClient(
9 option.WithAPIKey(os.Getenv("DETECTANT_API_KEY")),
10)

Scan one file

1file, err := os.Open("./invoice.pdf")
2if err != nil {
3 log.Fatal(err)
4}
5defer file.Close()
6
7result, err := client.Scan(context.Background(), file)
8if err != nil {
9 log.Fatal(err)
10}
11
12fmt.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.

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

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.