diff pkg/imports/sr.go @ 1225:4d7c44f7044e

Factored out som zip lookup code to be reusable in sounding result upload controller.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 19 Nov 2018 17:28:35 +0100
parents bc4b642c8d04
children d842d9d10872
line wrap: on
line diff
--- a/pkg/imports/sr.go	Mon Nov 19 17:14:42 2018 +0100
+++ b/pkg/imports/sr.go	Mon Nov 19 17:28:35 2018 +0100
@@ -152,7 +152,7 @@
 	defer z.Close()
 
 	feedback.Info("Looking for 'meta.json'")
-	mf := find("meta.json", z.File)
+	mf := common.FindInZIP(z, "meta.json")
 	if mf == nil {
 		return errors.New("Cannot find 'meta.json'")
 	}
@@ -167,7 +167,7 @@
 	}
 
 	feedback.Info("Looking for '*.xyz'")
-	xyzf := find(".xyz", z.File)
+	xyzf := common.FindInZIP(z, ".xyz")
 	if xyzf == nil {
 		return errors.New("Cannot find any *.xyz file")
 	}
@@ -273,16 +273,6 @@
 	return os.RemoveAll(string(sr))
 }
 
-func find(needle string, haystack []*zip.File) *zip.File {
-	needle = strings.ToLower(needle)
-	for _, straw := range haystack {
-		if strings.HasSuffix(strings.ToLower(straw.Name), needle) {
-			return straw
-		}
-	}
-	return nil
-}
-
 func loadMeta(f *zip.File) (*models.SoundingResultMeta, error) {
 	r, err := f.Open()
 	if err != nil {
@@ -345,12 +335,12 @@
 }
 
 func loadBoundary(z *zip.ReadCloser) (Polygon, error) {
-	shpF := find(".shp", z.File)
+	shpF := common.FindInZIP(z, ".shp")
 	if shpF == nil {
 		return nil, nil
 	}
 	prefix := strings.TrimSuffix(shpF.Name, path.Ext(shpF.Name))
-	dbfF := find(prefix+".dbf", z.File)
+	dbfF := common.FindInZIP(z, prefix+".dbf")
 	if dbfF == nil {
 		return nil, fmt.Errorf("No DBF file found for %s", shpF.Name)
 	}