comparison pkg/wfs/global.go @ 2719:2b6f73c30016

WFS downloader: Add BasicAuth support for downloading. TODO: Use it.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 19 Mar 2019 12:20:54 +0100
parents 3956de9b6b32
children 04876d865528
comparison
equal deleted inserted replaced
2718:eae8ec732101 2719:2b6f73c30016
38 } 38 }
39 ) 39 )
40 40
41 type ( 41 type (
42 Downloader interface { 42 Downloader interface {
43 Download(handler func(string, io.Reader) error) error 43 Download(user, password string, handler func(string, io.Reader) error) error
44 } 44 }
45 45
46 GeoJSONDownloader []string 46 GeoJSONDownloader []string
47 GMLDownloader []string 47 GMLDownloader []string
48 ) 48 )
83 FormatGML, 83 FormatGML,
84 sortBy) 84 sortBy)
85 return GMLDownloader(urls), err 85 return GMLDownloader(urls), err
86 } 86 }
87 87
88 func (gjd GeoJSONDownloader) Download(handler func(string, io.Reader) error) error { 88 func (gjd GeoJSONDownloader) Download(user, password string, handler func(string, io.Reader) error) error {
89 return DownloadURLs([]string(gjd), handler) 89 return DownloadURLs(user, password, []string(gjd), handler)
90 } 90 }
91 91
92 func places(n int) int { 92 func places(n int) int {
93 places := 1 93 places := 1
94 if n < 0 { 94 if n < 0 {
99 places++ 99 places++
100 } 100 }
101 return places 101 return places
102 } 102 }
103 103
104 func (gmd GMLDownloader) Download(handler func(string, io.Reader) error) error { 104 func (gmd GMLDownloader) Download(user, password string, handler func(string, io.Reader) error) error {
105 105
106 if len(gmd) == 0 { 106 if len(gmd) == 0 {
107 return errors.New("Nothing to download") 107 return errors.New("Nothing to download")
108 } 108 }
109 109
117 117
118 var files []string 118 var files []string
119 119
120 for i, url := range gmd { 120 for i, url := range gmd {
121 fname := filepath.Join(dlDir, fmt.Sprintf("%0*d.gml", digits, i)) 121 fname := filepath.Join(dlDir, fmt.Sprintf("%0*d.gml", digits, i))
122 if err := downloadURL(url, func(_ string, r io.Reader) error { 122 if err := downloadURL(user, password, url, func(_ string, r io.Reader) error {
123 f, err := os.Create(fname) 123 f, err := os.Create(fname)
124 if err != nil { 124 if err != nil {
125 return err 125 return err
126 } 126 }
127 if _, err = io.Copy(f, r); err != nil { 127 if _, err = io.Copy(f, r); err != nil {