Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
out, err := os.Create("result.txt")
if err != nil {
return err
}
defer out.Close()
resp, err := http.Get(u)
if err != nil {
return err
}
defer func() {
io.Copy(io.Discard, resp.Body)
resp.Body.Close()
}()
if resp.StatusCode != 200 {
return fmt.Errorf("Status: %v", resp.Status)
}
_, err = io.Copy(out, resp.Body)
if err != nil {
return err
}