-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathskywalkerExample_test.go
57 lines (49 loc) · 1.29 KB
/
skywalkerExample_test.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
//Copyright (c) 2017, Will Dixon. All rights reserved.
//Use of this source code is governed by a BSD-style
//license that can be found in the LICENSE file.
package skywalker_test
import (
"fmt"
"sort"
"strings"
"sync"
"github.com/dixonwille/skywalker"
)
type ExampleWorker struct {
*sync.Mutex
found []string
}
func (ew *ExampleWorker) Work(path string) {
//This is where the necessary work should be done.
//This will get concurrently so make sure it is thread safe if you need info across threads.
ew.Lock()
defer ew.Unlock()
ew.found = append(ew.found, path)
}
func ExampleSkywalker() {
//Following two functions are only to create and destroy data for the example
defer teardownData()
standupData()
ew := new(ExampleWorker)
ew.Mutex = new(sync.Mutex)
//root is the root directory of the data that was stood up above
sw := skywalker.New(root, ew)
sw.DirListType = skywalker.LTBlacklist
sw.DirList = []string{"sub"}
sw.ExtListType = skywalker.LTWhitelist
sw.ExtList = []string{".pdf"}
err := sw.Walk()
if err != nil {
fmt.Println(err)
return
}
sort.Sort(sort.StringSlice(ew.found))
for _, f := range ew.found {
show := strings.Replace(f, sw.Root, "", 1)
show = strings.Replace(show, "\\", "/", -1)
fmt.Println(show)
}
// Output:
// /subfolder/few.pdf
// /the/few.pdf
}