comparison pkg/wfs/download.go @ 2106:2b72f5e005aa

WFS imports: Write get GetFeature URLs into import log.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 04 Feb 2019 15:49:17 +0100
parents 8b7dee291488
children 86c88fc0ff5e
comparison
equal deleted inserted replaced
2105:58a28715e386 2106:2b72f5e005aa
244 } 244 }
245 245
246 return downloadURLs, nil 246 return downloadURLs, nil
247 } 247 }
248 248
249 func downloadURL(url string, handler func(io.Reader) error) error { 249 func downloadURL(url string, handler func(string, io.Reader) error) error {
250 resp, err := http.Get(url) 250 resp, err := http.Get(url)
251 if err != nil { 251 if err != nil {
252 return err 252 return err
253 } 253 }
254 if resp.StatusCode < 200 || resp.StatusCode > 299 { 254 if resp.StatusCode < 200 || resp.StatusCode > 299 {
255 return fmt.Errorf("Invalid HTTP status code: %d (%s)", 255 return fmt.Errorf("Invalid HTTP status code: %d (%s)",
256 resp.StatusCode, resp.Status) 256 resp.StatusCode, resp.Status)
257 } 257 }
258 defer resp.Body.Close() 258 defer resp.Body.Close()
259 return handler(resp.Body) 259 return handler(url, resp.Body)
260 } 260 }
261 261
262 // DownloadURLs does the actual GetFeature requests downloads 262 // DownloadURLs does the actual GetFeature requests downloads
263 // and hands the resulting io.Readers over to the given handler. 263 // and hands the resulting io.Readers over to the given handler.
264 func DownloadURLs(urls []string, handler func(io.Reader) error) error { 264 func DownloadURLs(urls []string, handler func(string, io.Reader) error) error {
265 for _, url := range urls { 265 for _, url := range urls {
266 if err := downloadURL(url, handler); err != nil { 266 if err := downloadURL(url, handler); err != nil {
267 return err 267 return err
268 } 268 }
269 } 269 }