Why does my Go HTTP server freeze when I call another API inside a goroutine?
func handler(w http.ResponseWriter, r *http.Request) {
go func() {
resp, err := http.Get("https://example.com/data")
if err != nil {
log.Println("request failed:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
log.Println("result:", string(body))
}()
w.Write([]byte("OK"))
}