func saveResult(name string, reader io.Reader) { if i := strings.LastIndex(name, "/"); i >= 0 { name = name[i+1:] } f, err := os.Create(name) if err != nil { log.Debug("create:", name, err) return } io.Copy(f, reader) f.Close() }
func preOp(host string, uri string, params []string, save bool) { for i, p := range params { url := host + "/" + uri + p log.Debug("url:", url) req, err := http.NewRequest("GET", url, nil) if err != nil { log.Warn("http newrequest fail:", url, err) continue } resp, err := http.DefaultClient.Do(req) if err != nil { log.Warn("http get fail:", url, err) continue } if save { saveResult(uri+strconv.Itoa(i), resp.Body) } resp.Body.Close() } }