As the title describes i am trying to make an api call in golang that is compiled to wasm it works fine when it is run on a machine but returns a deadlock error all go routines asleep whenever i run it in the browser. Thanks.
func APIcall(url string) map[string]interface{} {
resp, err := http.Get(url)
if err != nil {
fmt.Println("Error:", err)
}
defer resp.Body.Close()
buffer := make([]byte, 1024)
var body string
for {
n, err := resp.Body.Read(buffer)
if err == io.EOF {
// Reached the end of the body
body += string(buffer[:n])
break
} else if err != nil {
fmt.Println("Error reading response:", err)
}
body += string(buffer[:n])
}
var result map[string]interface{}
err = json.Unmarshal([]byte(body), &result)
if err != nil {
log.Fatal(err)
}
results, ok := result["results"].([]interface{})
if !ok {
fmt.Println("Error:", "Could not cast 'results' to a slice of interfaces")
}
if len(results) == 0 {
fmt.Println("No results found in the response")
}
result = results[0].(map[string]interface{})
return result
}
I expect for a map to be returned but instead all i get are deadlock errors.