From 3a720c9d01d9f283a5e1cff3115158126531d3f0 Mon Sep 17 00:00:00 2001 From: hisham waleed karam Date: Sat, 6 Oct 2018 02:54:09 +0200 Subject: [PATCH] get list of supported files --- utils.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ vars.go | 1 + 2 files changed, 45 insertions(+) diff --git a/utils.go b/utils.go index c7faa5b..81bd858 100644 --- a/utils.go +++ b/utils.go @@ -2,6 +2,10 @@ package gismanager import ( "io/ioutil" + "os" + "path" + "path/filepath" + "strings" yaml "gopkg.in/yaml.v2" ) @@ -23,3 +27,43 @@ func FromConfig(configFile string) (config *ManagerConfig, err error) { config = &gpkgConfig return } +func isSupported(ext string) bool { + for _, a := range supportedEXT { + if a == ext { + return true + } + } + return false +} + +//GetGISFiles retrun List of All GIS Files in this path +func GetGISFiles(root string) ([]string, error) { + var files []string + fileInfo, statErr := os.Stat(root) + if statErr != nil { + return files, statErr + } + if !fileInfo.IsDir() { + files = append(files, fileInfo.Name()) + return files, nil + } + dirInfo, err := ioutil.ReadDir(root) + if err != nil { + return files, err + } + for _, file := range dirInfo { + if file.IsDir() { + subFiles, subErr := GetGISFiles(path.Join(root, file.Name())) + if subErr == nil { + files = append(files, subFiles...) + } + } else { + extension := strings.ToLower(filepath.Ext(file.Name())) + if isSupported(extension) { + files = append(files, file.Name()) + } + } + } + + return files, nil +} diff --git a/vars.go b/vars.go index 5031086..76b3920 100644 --- a/vars.go +++ b/vars.go @@ -3,6 +3,7 @@ package gismanager import "regexp" var pgRegex = regexp.MustCompile(`^\s?PG:\s?.*$`) +var supportedEXT = []string{".zip", ".json", ".geojson", ".gdb", "kml", ".shp"} const ( geopackageDriver = "GPKG"