golang get gold price
func getPrice() ([]byte, error) {
url := "https://www.goldapi.io/api/XAU/CNY"
method := "GET"
client := &http.Client{}
req, err := http.NewRequest(method, url, nil)
if err != nil {
return nil, err
}
//change your token
req.Header.Add("x-access-token", "goldapi-55555555555555-io")
res, err := client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
return body, nil
}