helpers.go 646 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package main
  2. import (
  3. "io"
  4. "net"
  5. "net/http"
  6. "os"
  7. )
  8. func getMacAddr() ([]string, error) {
  9. ifas, err := net.Interfaces()
  10. if err != nil {
  11. return nil, err
  12. }
  13. var as []string
  14. for _, ifa := range ifas {
  15. a := ifa.HardwareAddr.String()
  16. if a != "" {
  17. as = append(as, a)
  18. }
  19. }
  20. return as, nil
  21. }
  22. func DownloadFile(filepath string, url string) error {
  23. // Get the data
  24. resp, err := http.Get(url)
  25. if err != nil {
  26. return err
  27. }
  28. defer resp.Body.Close()
  29. // Create the file
  30. out, err := os.Create(filepath)
  31. if err != nil {
  32. return err
  33. }
  34. defer out.Close()
  35. // Write the body to file
  36. _, err = io.Copy(out, resp.Body)
  37. return err
  38. }