-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
57 lines (45 loc) · 1.13 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
package main
import (
"flag"
"log"
"os"
"plugin"
)
func main() {
var (
path string
pluginPath string
)
flag.StringVar(&path, "path", "", "specify the path to the file/directory to monitor")
flag.StringVar(&pluginPath, "plugin", "", "path to the plugin to load (.so)")
flag.Parse()
if len(path) == 0 {
log.Fatal("missing file/directory path")
}
if len(pluginPath) == 0 {
log.Fatal("missing plugin path")
}
p, err := plugin.Open(pluginPath)
if err != nil {
log.Fatalf("failed to open plugin (%s): %s", pluginPath, err)
}
if p == nil {
log.Fatal("unexpected error occurred, failed to open go plugin")
}
handle, err := p.Lookup("Handle")
if err != nil {
log.Fatalf("unable to find symbol 'Handle': %s", err)
}
if handle == nil {
log.Fatal("unexpected error occurred, failed to retrieve expected function")
}
handler, ok := handle.(func(string, string, string))
if !ok {
log.Fatal("unable to retrieve from symbol 'Handle', a function with the following signature: func(string, string, string)")
}
app, err := newClaptrap(path, handler)
if err != nil {
log.Fatal(err)
}
os.Exit(app.trap())
}