swift-like.txt 427 B

123456789101112131415
  1. func makeRequest(method string, url string, cb func(error, io.ReadCloser)) {
  2. req, _ := http.NewRequest(method, url, nil)
  3. resp, err := http.DefaultClient.Do(req)
  4. if err != nil {
  5. cb(err, nil)
  6. } else {
  7. cb(err, resp.Body)
  8. }
  9. }
  10. func main() {
  11. makeRequest("GET", "http://ipinfo.io/json", func(err error, body io.ReadCloser) {
  12. defer body.Close()
  13. io.Copy(os.Stdout, body)
  14. })
  15. }