common.go 613 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package mc
  2. import (
  3. "io"
  4. "io/ioutil"
  5. "net/http"
  6. "os"
  7. )
  8. func httpReq(url string) []byte {
  9. resp, err := http.Get(url)
  10. if err != nil {
  11. print(err)
  12. }
  13. defer resp.Body.Close()
  14. body, err := ioutil.ReadAll(resp.Body)
  15. if err != nil {
  16. print(err)
  17. }
  18. return body
  19. }
  20. func downloadFile(filepath string, url string) error {
  21. // Get the data
  22. resp, err := http.Get(url)
  23. if err != nil {
  24. return err
  25. }
  26. defer resp.Body.Close()
  27. // Create the file
  28. out, err := os.Create(filepath)
  29. if err != nil {
  30. return err
  31. }
  32. defer out.Close()
  33. // Write the body to file
  34. _, err = io.Copy(out, resp.Body)
  35. return err
  36. }