-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
100 lines (78 loc) · 2 KB
/
options.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package fswatch
// #include <stdlib.h>
// #include <libfswatch/c/libfswatch.h>
import "C"
// Option instances allow to configure monitors.
type Option func(h *opt) error
// opt contains the available options.
type opt struct {
monitorType C.enum_fsw_monitor_type
properties map[*C.char]*C.char
allowOverflow bool
latency C.double
recursive bool
directoryOnly bool
followSymlinks bool
eventTypes []EventType
filters []C.fsw_cmonitor_filter
}
func WithMonitorType(monitorType MonitorType) Option {
return func(o *opt) error {
o.monitorType = C.enum_fsw_monitor_type(monitorType)
return nil
}
}
func WithProperties(properties map[string]string) Option {
return func(o *opt) error {
o.properties = make(map[*C.char]*C.char, len(properties))
for k, v := range properties {
o.properties[C.CString(k)] = C.CString(v)
}
return nil
}
}
func WithAllowOverflow(allowOverflow bool) Option {
return func(o *opt) error {
o.allowOverflow = allowOverflow
return nil
}
}
func WithLatency(latency float64) Option {
return func(o *opt) error {
o.latency = C.double(latency)
return nil
}
}
func WithRecursive(recursive bool) Option {
return func(o *opt) error {
o.recursive = recursive
return nil
}
}
func WithDirectoryOnly(directoryOnly bool) Option {
return func(o *opt) error {
o.directoryOnly = directoryOnly
return nil
}
}
func WithFollowSymlinks(followSymlinks bool) Option {
return func(o *opt) error {
o.followSymlinks = followSymlinks
return nil
}
}
func WithEventTypeFilters(eventTypes []EventType) Option {
return func(o *opt) error {
o.eventTypes = eventTypes
return nil
}
}
func WithFilters(filters []Filter) Option {
return func(o *opt) error {
o.filters = make([]C.fsw_cmonitor_filter, len(filters))
for i, f := range filters {
o.filters[i] = C.fsw_cmonitor_filter{text: C.CString(f.Text), _type: C.enum_fsw_filter_type(f.FilterType), case_sensitive: C.bool(f.CaseSensitive), extended: C.bool(f.Extended)}
}
return nil
}
}