-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
60 lines (51 loc) · 1.06 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"github.com/tidwall/gjson"
)
var src = "./files/"
var custom = "./custom/"
var dst = "/files"
var out = "./list.json"
// Result is a single geojson search result
type Result struct {
Name string `json:"name"`
ID string `json:"id"`
Tag string `json:"tag"`
}
func main() {
files, err := ioutil.ReadDir(src)
if err != nil {
panic(err)
}
custom, err := ioutil.ReadDir(custom)
if err != nil {
panic(err)
}
files = append(files, custom...)
var results []Result
for _, f := range files {
file, err := os.Open(fmt.Sprintf("%s/%s", src, f.Name()))
if err != nil {
log.Fatal(err)
}
defer file.Close()
buf, _ := ioutil.ReadAll(file)
str := string(buf)
name := gjson.Get(str, "properties.name").String()
id := gjson.Get(str, "properties.id").String()
tag := gjson.Get(str, "properties.type").String()
res := Result{
Name: name,
ID: id,
Tag: tag,
}
results = append(results, res)
}
wr, _ := json.Marshal(results)
_ = ioutil.WriteFile(out, wr, 0644)
}