# HG changeset patch # User Sascha L. Teichmann # Date 1632153729 -7200 # Node ID 09346efa7f699ed88b09f1ee059c9aaf99384b39 # Parent 5f47eeea988ddb59a16f535a264e6dde0396ea9e Do ogr2ogr check only once when it's needed the first time. diff -r 5f47eeea988d -r 09346efa7f69 pkg/wfs/global.go --- a/pkg/wfs/global.go Mon Sep 20 17:45:39 2021 +0200 +++ b/pkg/wfs/global.go Mon Sep 20 18:02:09 2021 +0200 @@ -21,6 +21,7 @@ "os" "os/exec" "path/filepath" + "sync" "gemma.intevation.de/gemma/pkg/config" "gemma.intevation.de/gemma/pkg/log" @@ -53,17 +54,30 @@ GMLDownloader []string ) -// GetFeatures is the default Downloader in this Gemma server. -var GetFeatures = setup() +var ( + getFeaturesOnce sync.Once + getFeatures func(*Capabilities, string, string) (Downloader, error) +) -func setup() func(*Capabilities, string, string) (Downloader, error) { +func getFeaturesOnceFunc() { path, err := exec.LookPath("ogr2ogr") if err != nil { log.Infoln("ogr2ogr not installed. Using direct GeoJSON WFS download.") - return getFeaturesGeoJSON + getFeatures = getFeaturesGeoJSON + } else { + log.Infof("ogr2ogr found at %s. Using GML WFS download.\n", path) + getFeatures = getFeaturesGML } - log.Infof("ogr2ogr found at %s. Using GML WFS download.\n", path) - return getFeaturesGML +} + +// GetFeatures is the default Downloader in this Gemma server. +func GetFeatures( + caps *Capabilities, + featureTypeName string, + sortBy string, +) (Downloader, error) { + getFeaturesOnce.Do(getFeaturesOnceFunc) + return getFeatures(caps, featureTypeName, sortBy) } func getFeaturesGeoJSON(