Hello mates, I am getting data like the following below using Regex, nevertheless I think that is not the best way to get these infos.
{"transactions": [{
"bytes":null,
"length":1,
"time":"1653228731.000000",
"name":"Test",
"status":"success",
"transfers":[{
"id":"3",
"amount":3930,
"approval":false
}
}
Using GetXML to get the data as a string, and after selecting each specific info using Regex.
func getXML(url string) (string, error) {
resp, err := http.Get(url)
if err != nil {
return "", fmt.Errorf("GET error: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("Status error: %v", resp.StatusCode)
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("Read body: %v", err)
}
return string(data), nil
}
Example of Regex: regexp.MustCompile(`"name":"\s*(.*?)\s*"`)
Well, I feel that is not the most common and efficient manner to get these infos. Probably exist something similar to GetEnv(“name”) that do this for http requests.
Anyone could help me?