Go Currency Converter

PHOTO EMBED

Tue Aug 08 2023 08:07:35 GMT+0000 (Coordinated Universal Time)

Saved by @martechdev #go #currencyconverter #exchangerates #currency #api

package main

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

func main() {
    url := "https://api.currencyapi.com/v3/latest"
    method := "GET"

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

if err != nil {
    fmt.Println(err)
    return
}
req.Header.Add("apikey", "YOUR-API-KEY")

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))
}
content_copyCOPY

This snippet was copied from the currencyapi.com documentation. For Go, they specifically provide a snippet using a standard HTTP client.
https://currencyapi.com/docs/examples/go-currency-converter