Antivirus File Scanner API in Go

< Back to Guides

Go is a statically typed, compiled programming language. This tutorial is how to check a file for malware using Go.

Instructions

  1. Get a free API to use by signing up at FileScanAPI.com and replace REPLACE_ME with your API key.
  2. Update location value in payload with url location of your file.
  3. Update callback value in payload to your webhook url. We recommend using webhook.site as a callback url during test.

For 2 and 3, you can find this documented at Offical Documentation

 

Check file for virus in Go

package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.filescanapi.com/v1/file/async"
  method := "POST"

  payload := strings.NewReader(`{
    "location": "https://filescanapi.com/icon.png",
    "metadata": {
        "filename": "demo.png"
    },
    "callback": "https://webhook.site"
}`)

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("x-api-key", "REPLACE_ME")
  req.Header.Add("Content-Type", "application/json")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}