Quarantine an Infected File in Go

Cloudmersive
2 min readAug 18, 2021

When an infected file is located via a virus scan, proper containment steps need to be taken to ensure it doesn’t contaminate any other files or programs within your application. In this tutorial, we will demonstrate how to use an API in Go to quarantine a dangerous file by creating a zip archive and applying encryption and password protection.

To call the API function, all you need to do is input the password for the ZIP archive, the target file, and your API key into the following code:

package mainimport (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/convert/archive/zip/create/quarantine"
method := "POST"
payload := strings.NewReader("inputFile1=%3Cbinary%3E")client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("password", "<string>")
req.Header.Add("encryptionAlgorithm", "<string>")
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")
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))
}

The file or files that were flagged as threats will be efficiently separated and subdued. If you need to obtain an API key, you can do so by registering for a free account on the Cloudmersive website; this provides 800 monthly calls across our entire library of APIs.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.