-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.go
89 lines (68 loc) · 1.24 KB
/
index.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"encoding/json"
"fmt"
"github.com/gosexy/sugar"
"github.com/gosexy/yaml"
"github.com/gosexy/to"
"os"
"sort"
)
const PS = string(os.PathSeparator)
func getPlugins() []string {
plugins := []string{}
dh, err := os.Open(".")
if err != nil {
panic(err)
}
files, err := dh.Readdir(-1)
if err != nil {
panic(err)
}
var pkgfile string
for _, file := range files {
if file.IsDir() == true {
name := file.Name()
pkgfile = name + PS + "package.yaml"
_, err = os.Stat(pkgfile)
if err == nil {
plugins = append(plugins, name)
}
}
}
sort.Strings(plugins)
return plugins
}
func main() {
var response = []sugar.Tuple{}
names := getPlugins()
for _, name := range names {
file := name + PS + "package.yaml"
pkg, err := yaml.Open(file)
if err != nil {
panic(err)
}
item := sugar.Tuple{}
keys := []string{
"name",
"stable",
"latest",
"license",
"url",
"demo_url",
"description",
"author",
"copyright",
"packages",
}
item["pkg"] = name
for _, key := range keys {
item[key] = pkg.Get(key)
}
if to.Bool(pkg.Get("hidden")) == false {
response = append(response, item)
}
}
data, _ := json.Marshal(response)
fmt.Printf("%s", string(data))
}