saveDebug writes the debug info specified in the argument fetching it from the host provided in the configuration
(sourceURL, filePath string, duration time.Duration)
| 50 | // saveDebug writes the debug info specified in the argument fetching it from the host |
| 51 | // provided in the configuration |
| 52 | func saveDebug(sourceURL, filePath string, duration time.Duration) error { |
| 53 | var err error |
| 54 | var resp io.ReadCloser |
| 55 | |
| 56 | glog.Infof("fetching information over HTTP from %s", sourceURL) |
| 57 | if duration > 0 { |
| 58 | glog.Info(fmt.Sprintf("please wait... (%v)", duration)) |
| 59 | } |
| 60 | |
| 61 | timeout := duration + duration/2 + 2*time.Second |
| 62 | resp, err = fetchURL(sourceURL, timeout) |
| 63 | if err != nil { |
| 64 | return err |
| 65 | } |
| 66 | defer func() { |
| 67 | if err := resp.Close(); err != nil { |
| 68 | glog.Warningf("error closing resp reader: %v", err) |
| 69 | } |
| 70 | }() |
| 71 | out, err := os.Create(filePath) |
| 72 | if err != nil { |
| 73 | return fmt.Errorf("error while creating debug file: %s", err) |
| 74 | } |
| 75 | defer func() { |
| 76 | out.Close() |
| 77 | }() |
| 78 | _, err = io.Copy(out, resp) |
| 79 | return err |
| 80 | } |
| 81 | |
| 82 | // fetchURL fetches a profile from a URL using HTTP. |
| 83 | func fetchURL(source string, timeout time.Duration) (io.ReadCloser, error) { |