comparison pkg/wfs/global.go @ 4166:04876d865528

Made 'golint' and 'staticcheck' happy with wfs package.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 05 Aug 2019 14:35:54 +0200
parents 2b6f73c30016
children 16259efa828f
comparison
equal deleted inserted replaced
4165:8dd59e2c9d3d 4166:04876d865528
26 26
27 "gemma.intevation.de/gemma/pkg/config" 27 "gemma.intevation.de/gemma/pkg/config"
28 ) 28 )
29 29
30 var ( 30 var (
31 // FormatGeoJSON is a list of MIME types of
32 // GeoJSON documents.
31 FormatGeoJSON = []string{"geojson", "application/json"} 33 FormatGeoJSON = []string{"geojson", "application/json"}
32 FormatGML = []string{ 34 // FormatGML is a list of MIME types
35 // GML documents.
36 FormatGML = []string{
33 "application/gml+xml; version=3.2", 37 "application/gml+xml; version=3.2",
34 "gml2", "gml3", "gml32", 38 "gml2", "gml3", "gml32",
35 "text/xml; subtype=gml/2.1.2", 39 "text/xml; subtype=gml/2.1.2",
36 "text/xml; subtype=gml/3.1.1", 40 "text/xml; subtype=gml/3.1.1",
37 "text/xml; subtype=gml/3.2", 41 "text/xml; subtype=gml/3.2",
38 } 42 }
39 ) 43 )
40 44
41 type ( 45 type (
46 // Downloader abstracts the idea of a download function for WFS.
42 Downloader interface { 47 Downloader interface {
43 Download(user, password string, handler func(string, io.Reader) error) error 48 Download(user, password string, handler func(string, io.Reader) error) error
44 } 49 }
45 50
51 // GeoJSONDownloader is a Downloader for GeoJSON.
46 GeoJSONDownloader []string 52 GeoJSONDownloader []string
47 GMLDownloader []string 53 // GMLDownloader is a Downloader for GML.
54 GMLDownloader []string
48 ) 55 )
49 56
57 // GetFeatures is the default Downloader in this Gemma server.
50 var GetFeatures = setup() 58 var GetFeatures = setup()
51 59
52 func setup() func(*Capabilities, string, string) (Downloader, error) { 60 func setup() func(*Capabilities, string, string) (Downloader, error) {
53 path, err := exec.LookPath("ogr2ogr") 61 path, err := exec.LookPath("ogr2ogr")
54 if err != nil { 62 if err != nil {
55 log.Println("info: ogr2ogr not installed. Using direct GeoJSON WFS download.") 63 log.Println("info: ogr2ogr not installed. Using direct GeoJSON WFS download.")
56 return GetFeaturesGeoJSON 64 return getFeaturesGeoJSON
57 } 65 }
58 log.Printf("info: ogr2ogr found at %s. Using GML WFS download.\n", path) 66 log.Printf("info: ogr2ogr found at %s. Using GML WFS download.\n", path)
59 return GetFeaturesGML 67 return getFeaturesGML
60 } 68 }
61 69
62 func GetFeaturesGeoJSON( 70 func getFeaturesGeoJSON(
63 caps *Capabilities, 71 caps *Capabilities,
64 featureTypeName string, 72 featureTypeName string,
65 sortBy string, 73 sortBy string,
66 ) (Downloader, error) { 74 ) (Downloader, error) {
67 urls, err := GetFeaturesGET( 75 urls, err := GetFeaturesGET(
70 FormatGeoJSON, 78 FormatGeoJSON,
71 sortBy) 79 sortBy)
72 return GeoJSONDownloader(urls), err 80 return GeoJSONDownloader(urls), err
73 } 81 }
74 82
75 func GetFeaturesGML( 83 func getFeaturesGML(
76 caps *Capabilities, 84 caps *Capabilities,
77 featureTypeName string, 85 featureTypeName string,
78 sortBy string, 86 sortBy string,
79 ) (Downloader, error) { 87 ) (Downloader, error) {
80 urls, err := GetFeaturesGET( 88 urls, err := GetFeaturesGET(
83 FormatGML, 91 FormatGML,
84 sortBy) 92 sortBy)
85 return GMLDownloader(urls), err 93 return GMLDownloader(urls), err
86 } 94 }
87 95
96 // Download is the GeoJSON implementation of the Downloader.
88 func (gjd GeoJSONDownloader) Download(user, password string, handler func(string, io.Reader) error) error { 97 func (gjd GeoJSONDownloader) Download(user, password string, handler func(string, io.Reader) error) error {
89 return DownloadURLs(user, password, []string(gjd), handler) 98 return DownloadURLs(user, password, []string(gjd), handler)
90 } 99 }
91 100
92 func places(n int) int { 101 func places(n int) int {
99 places++ 108 places++
100 } 109 }
101 return places 110 return places
102 } 111 }
103 112
113 // Download is GML implementaion of the Downloader.
104 func (gmd GMLDownloader) Download(user, password string, handler func(string, io.Reader) error) error { 114 func (gmd GMLDownloader) Download(user, password string, handler func(string, io.Reader) error) error {
105 115
106 if len(gmd) == 0 { 116 if len(gmd) == 0 {
107 return errors.New("Nothing to download") 117 return errors.New("nothing to download")
108 } 118 }
109 119
110 tmpDir := config.TmpDir() 120 tmpDir := config.TmpDir()
111 dlDir, err := ioutil.TempDir(tmpDir, "wfs-downloads") 121 dlDir, err := ioutil.TempDir(tmpDir, "wfs-downloads")
112 if err != nil { 122 if err != nil {