-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
86 lines (73 loc) · 1.46 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
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
package main
import (
"bytes"
"encoding/json"
"fmt"
"html/template"
"io"
"io/ioutil"
"log"
"os"
"path"
)
type Package struct {
Repo string
Path string
Packages []string
Url string
}
func writePage(w io.Writer, path string, pkg Package) error {
t, err := template.ParseFiles("layouts/gorepos.html")
if err != nil {
return err
}
pkg.Path = path
var page bytes.Buffer
err = t.Execute(&page, pkg)
if err != nil {
return err
}
_, err = io.Copy(w, &page)
return err
}
func loadConfig(namespace string) (ret []Package, err error) {
content, err := ioutil.ReadFile(fmt.Sprintf("%s.json", namespace))
if err != nil {
return
}
err = json.Unmarshal(content, &ret)
return
}
func main() {
if len(os.Args) != 3 {
fmt.Printf("main.go namespace fs-root-dir\n")
}
namespace := os.Args[1]
root := os.Args[2]
packages, err := loadConfig(namespace)
if err != nil {
log.Fatalf("%s\n", err)
return
}
for _, pkg := range packages {
packages := pkg.Packages
packages = append(packages, "")
for _, subpackage := range packages {
pkgpath := path.Join(namespace, pkg.Path)
root := path.Join(root, pkg.Path, subpackage)
if err := os.MkdirAll(root, 0755); err != nil {
fmt.Errorf("%s\n", err)
return
}
fd, err := os.Create(path.Join(root, "index.html"))
if err != nil {
fmt.Errorf("%s\n", err)
return
}
defer fd.Close()
writePage(fd, pkgpath, pkg)
fd.Close()
}
}
}
// vim: foldmethod=marker