-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilehandler.go
More file actions
35 lines (30 loc) · 855 Bytes
/
filehandler.go
File metadata and controls
35 lines (30 loc) · 855 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
package main
import "os"
var allfiles []filedata
type filedata struct {
fpath string
fname string
}
//callback for walk needs to match the following:
//type WalkFunc func(path string, info os.FileInfo, err error) error
func readFile(path string, fi os.FileInfo, _ error) error {
switch mode := fi.Mode(); {
case mode.IsRegular():
allfiles = extendFileDataSlice(allfiles, filedata{path, fi.Name()})
}
return nil
}
//ExtendEntitySlice extends a slice of type EntityData
func extendFileDataSlice(slice []filedata, fd filedata) []filedata {
n := len(slice)
if n == cap(slice) {
// Slice is full; must grow.kb
// We double its size and add 1, so if the size is zero we still grow.
newSlice := make([]filedata, len(slice), 2*len(slice)+1)
copy(newSlice, slice)
slice = newSlice
}
slice = slice[0 : n+1]
slice[n] = fd
return slice
}