comparison pkg/wfs/download.go @ 1624:943823d03d50

WFS downloader: Started with mapping return features to Go structs.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 18 Dec 2018 18:36:02 +0100
parents 3093bab05c81
children 92da44ba610c
comparison
equal deleted inserted replaced
1623:20c98c2964f7 1624:943823d03d50
16 import ( 16 import (
17 "bufio" 17 "bufio"
18 "encoding/xml" 18 "encoding/xml"
19 "errors" 19 "errors"
20 "fmt" 20 "fmt"
21 "io"
21 "log" 22 "log"
22 "net/http" 23 "net/http"
23 "net/url" 24 "net/url"
24 "strconv" 25 "strconv"
25 26
233 downloadURLs = []string{q.String()} 234 downloadURLs = []string{q.String()}
234 } 235 }
235 236
236 return downloadURLs, nil 237 return downloadURLs, nil
237 } 238 }
239
240 func downloadURL(url string, handler func(io.Reader) error) error {
241 resp, err := http.Get(url)
242 if err != nil {
243 return err
244 }
245 defer resp.Body.Close()
246 return handler(resp.Body)
247 }
248
249 func DownloadURLs(urls []string, handler func(io.Reader) error) error {
250 for _, url := range urls {
251 if err := downloadURL(url, handler); err != nil {
252 return nil
253 }
254 }
255 return nil
256 }