-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetCurrencyRate.go
41 lines (34 loc) · 1002 Bytes
/
GetCurrencyRate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Get API key at www.interzoid.com/register
package main
import (
"encoding/json"
"fmt"
"net/http"
)
type Payload struct {
Symbol string
Name string
Country string
Rate string
Code string
Credits int
}
func main() {
// Create the struct variable to store the decoded JSON response
thePayload := Payload{}
// Call the API
// Can error check here too replacing underscore with 'err'
response, _ := http.Get("https://api.interzoid.com/getcurrencyrate?license=
YOURAPILICENSEKEY&symbol=GBP")
if response.StatusCode != 200 {
// Report any HTTP Errors
fmt.Println("Error: ", response.Status)
} else {
// Decode the JSON and print a comma-delimited response,
// one of many ways to format the response
_ = json.NewDecoder(response.Body).Decode(&thePayload)
fmt.Println(thePayload.Symbol + "," + thePayload.Name +
"," + thePayload.Country +
"," + thePayload.Rate)
}
}