forked from premendrasingh/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opts.go
56 lines (48 loc) · 1.31 KB
/
opts.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
package publisher
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/op"
)
// ClientOption allows API users to set additional options when publishing events.
type ClientOption func(option Context) ([]common.MapStr, Context)
// Guaranteed option will retry publishing the event, until send attempt have
// been ACKed by output plugin.
func Guaranteed(o Context) ([]common.MapStr, Context) {
o.Guaranteed = true
return nil, o
}
// Sync option will block the event publisher until an event has been ACKed by
// the output plugin or failed.
func Sync(o Context) ([]common.MapStr, Context) {
o.Sync = true
return nil, o
}
func Signal(signaler op.Signaler) ClientOption {
return func(ctx Context) ([]common.MapStr, Context) {
if ctx.Signal == nil {
ctx.Signal = signaler
} else {
ctx.Signal = op.CombineSignalers(ctx.Signal, signaler)
}
return nil, ctx
}
}
func Metadata(m common.MapStr) ClientOption {
if len(m) == 0 {
return nilOption
}
return func(ctx Context) ([]common.MapStr, Context) {
return []common.MapStr{m}, ctx
}
}
func MetadataBatch(m []common.MapStr) ClientOption {
if len(m) == 0 {
return nilOption
}
return func(ctx Context) ([]common.MapStr, Context) {
return m, ctx
}
}
func nilOption(o Context) ([]common.MapStr, Context) {
return nil, o
}