-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcollection.go
More file actions
49 lines (33 loc) · 924 Bytes
/
collection.go
File metadata and controls
49 lines (33 loc) · 924 Bytes
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
package hammock
import (
"fmt"
"os"
"path/filepath"
"strings"
)
type designDocCollection struct {
Documents map[string]*designDocument
}
func newDesignDocCollection() *designDocCollection {
return &designDocCollection{Documents: map[string]*designDocument{}}
}
func (data *designDocCollection) loadFromDisk(designs_root string) error {
// read all design docs saved at designs_root
err := filepath.Walk(designs_root, func(path string, f os.FileInfo, err error) error {
if path == designs_root {
return nil
}
if f.IsDir() {
parts := strings.Split(path, string(filepath.Separator))
num_parts := len(parts)
doc_name := fmt.Sprintf("_design/%v", parts[num_parts-1])
if _, ok := data.Documents[doc_name]; !ok {
data.Documents[doc_name] = newDesignDocument(doc_name)
}
data.Documents[doc_name].loadFromDisk(path)
return filepath.SkipDir
}
return nil
})
return err
}