File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "log"
5+ "os"
6+ "path/filepath"
7+ "regexp"
8+
9+ "github.com/FourtekIT/devnagri-cli/config"
10+ "github.com/Jeffail/gabs"
11+ )
12+
13+ func main () {
14+
15+ }
16+
17+ func visit (files * []string ) filepath.WalkFunc {
18+ return func (path string , info os.FileInfo , err error ) error {
19+ if err != nil {
20+ log .Fatal (err )
21+ }
22+ * files = append (* files , path )
23+ return nil
24+ }
25+ }
26+
27+ func requiredExtensionFiles (files []string , extension string ) []string {
28+
29+ extensionRegexp := ".*." + extension + "$"
30+
31+ var reqFiles []string
32+ for _ , file := range files {
33+
34+ matches , _ := regexp .MatchString (extensionRegexp , file )
35+ if matches == true {
36+ reqFiles = append (reqFiles , file )
37+
38+ }
39+ }
40+ return reqFiles
41+ }
42+
43+ func jsonListofFiles (files []string ) string {
44+
45+ // TODO Change the following to be initialized form the calling location
46+ var allFiles []string
47+
48+ RootDir := config .FetchAndValidate ("RootDir" ) // returns string
49+ //root := "./en"
50+ Extension := config .FetchAndValidate ("Extension" )
51+ //extension := "pdf"
52+
53+ err := filepath .Walk (RootDir , visit (& allFiles ))
54+ if err != nil {
55+ panic (err )
56+ }
57+
58+ reqFiles := requiredExtensionFiles (allFiles , Extension )
59+ //fmt.Println(reqFiles)
60+
61+ jsonObj := gabs .New ()
62+ jsonObj .Set (reqFiles )
63+ //fmt.Println(jsonObj.String())
64+
65+ // Return the list of files as a json structure
66+ return jsonObj .String ()
67+
68+ }
You can’t perform that action at this time.
0 commit comments