-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bulkfilehandler.go
67 lines (62 loc) · 1.25 KB
/
bulkfilehandler.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
package main
import (
"fmt"
"os"
)
type contenterror struct {
content string
err error
fname string
}
func extractAndAnalyse(filepool []filedata) (bool, error) {
//make channel run goroutine...
ch := make(chan contenterror)
for _, fi := range filepool {
go getFileContent(fi, ch)
}
for range filepool {
ce := <-ch
if ce.err != nil {
logFileMessage("INFO: '%s' cannot be handled by Tika.", ce.fname)
} else {
httpScanner(ce.fname, ce.content)
}
}
return false, nil
}
func openFile(path string) (*os.File, error) {
fp, err := os.Open(path)
if err != nil {
return nil, err
}
return fp, nil
}
func getFileContent(fi filedata, ch chan contenterror) {
//create empty struct to return...
var ce contenterror
ce.fname = fi.fname
//what are we doing..?
logFileMessage("INFO: '%s' being processed.", fi.fname)
//process...
fp, err := openFile(fi.fpath)
defer fp.Close()
if err != nil {
ce.err = err
ch <- ce
return
}
_, flRecursiveKeysValues, err := getTikaRecursive(fi.fname, fp, acceptJSON)
if err != nil {
ce.err = err
ch <- ce
return
}
if val, ok := flRecursiveKeysValues[tikaPlainText]; ok {
ce.content = val.(string)
ch <- ce
return
}
ce.err = fmt.Errorf("No plain text data to analyse.")
ch <- ce
return
}