How to Get a PNG Icon File for a File Extension using Go
Like many widely used proprietary materials, most file types have an accompanying icon (or logo) which serves to visually represent their 3 to 4-character file extension for marketing purposes. There’s a practical use for these in a professional context, too: when we need to allude to certain file extensions in our presentations, thumbnails, and other important client-facing materials, it’s a great idea to represent file extensions with their dedicated PNG icons alone; doing so yields a more stimulating & interactive experience for our viewers.
With our “Get PNG Icon” API, you can quickly & easily generate these PNG icons for more than 100 common file formats (unsupported formats will receive a generic icon) and make shrewd use of them in your own materials. The great thing is this API is free to use; all you need to do is register a free account on our website to get your API key, and then follow instructions provided below to structure your API call using complementary, ready-to-run code examples in Go.
To call this API, copy the code examples below into your file and include your API key in the appropriate header. After that, you’ll need to specify your desired file extension as a string, and then include an integer to define the size you want the resulting icon to be (preserving aspect ratio).
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.cloudmersive.com/convert/autodetect/get-icon"
method := "POST"
client := &http.Client {
}
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("fileExtension", "<string>")
req.Header.Add("iconSize", "<integer>")
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))
}
That’s all there is to it — no more code required!