Mercurial > gemma
comparison pkg/wfs/global.go @ 5491:09346efa7f69 logging
Do ogr2ogr check only once when it's needed the first time.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 20 Sep 2021 18:02:09 +0200 |
parents | 5f47eeea988d |
children | 31973f6f5cca |
comparison
equal
deleted
inserted
replaced
5490:5f47eeea988d | 5491:09346efa7f69 |
---|---|
19 "io" | 19 "io" |
20 "io/ioutil" | 20 "io/ioutil" |
21 "os" | 21 "os" |
22 "os/exec" | 22 "os/exec" |
23 "path/filepath" | 23 "path/filepath" |
24 "sync" | |
24 | 25 |
25 "gemma.intevation.de/gemma/pkg/config" | 26 "gemma.intevation.de/gemma/pkg/config" |
26 "gemma.intevation.de/gemma/pkg/log" | 27 "gemma.intevation.de/gemma/pkg/log" |
27 ) | 28 ) |
28 | 29 |
51 GeoJSONDownloader []string | 52 GeoJSONDownloader []string |
52 // GMLDownloader is a Downloader for GML. | 53 // GMLDownloader is a Downloader for GML. |
53 GMLDownloader []string | 54 GMLDownloader []string |
54 ) | 55 ) |
55 | 56 |
56 // GetFeatures is the default Downloader in this Gemma server. | 57 var ( |
57 var GetFeatures = setup() | 58 getFeaturesOnce sync.Once |
59 getFeatures func(*Capabilities, string, string) (Downloader, error) | |
60 ) | |
58 | 61 |
59 func setup() func(*Capabilities, string, string) (Downloader, error) { | 62 func getFeaturesOnceFunc() { |
60 path, err := exec.LookPath("ogr2ogr") | 63 path, err := exec.LookPath("ogr2ogr") |
61 if err != nil { | 64 if err != nil { |
62 log.Infoln("ogr2ogr not installed. Using direct GeoJSON WFS download.") | 65 log.Infoln("ogr2ogr not installed. Using direct GeoJSON WFS download.") |
63 return getFeaturesGeoJSON | 66 getFeatures = getFeaturesGeoJSON |
67 } else { | |
68 log.Infof("ogr2ogr found at %s. Using GML WFS download.\n", path) | |
69 getFeatures = getFeaturesGML | |
64 } | 70 } |
65 log.Infof("ogr2ogr found at %s. Using GML WFS download.\n", path) | 71 } |
66 return getFeaturesGML | 72 |
73 // GetFeatures is the default Downloader in this Gemma server. | |
74 func GetFeatures( | |
75 caps *Capabilities, | |
76 featureTypeName string, | |
77 sortBy string, | |
78 ) (Downloader, error) { | |
79 getFeaturesOnce.Do(getFeaturesOnceFunc) | |
80 return getFeatures(caps, featureTypeName, sortBy) | |
67 } | 81 } |
68 | 82 |
69 func getFeaturesGeoJSON( | 83 func getFeaturesGeoJSON( |
70 caps *Capabilities, | 84 caps *Capabilities, |
71 featureTypeName string, | 85 featureTypeName string, |