Convert USD to EUR in Go

Cloudmersive
1 min readMay 25, 2021

If you have an application that sells products or services to an international audience, utilizing an automatic currency conversion tool will ensure you always have the latest available exchange rate data. The following API will allow you to facilitate an improved customer experience by automatically converting a price in the source currency into the destination currency.

To call the currency conversion function, simply input the price, source currency ISO code, destination currency ISO code, and your API key into the following:

package mainimport (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/currency/exchange-rates/convert/%3Cstring%3E/to/%3Cstring%3E"
method := "POST"
payload := strings.NewReader(`"<double>"`)client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
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))
}

This will return a newly converted price in the destination currency, allowing for convenient and accommodating transactions for all nationalities.

--

--

Cloudmersive

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