1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
testing.go 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
package testing
// ChanClient implements Client interface, forwarding published events to some
import (
"github.com/elastic/beats/libbeat/beat"
)
type TestPublisher struct {
client beat.Client
}
// given channel only.
type ChanClient struct {
done chan struct{}
Channel chan beat.Event
}
func PublisherWithClient(client beat.Client) beat.Pipeline {
return &TestPublisher{client}
}
func (pub *TestPublisher) Connect() (beat.Client, error) {
return pub.client, nil
}
func (pub *TestPublisher) ConnectWith(_ beat.ClientConfig) (beat.Client, error) {
return pub.client, nil
}
func (pub *TestPublisher) SetACKHandler(_ beat.PipelineACKHandler) error {
panic("Not supported")
}
func NewChanClient(bufSize int) *ChanClient {
return NewChanClientWith(make(chan beat.Event, bufSize))
}
func NewChanClientWith(ch chan beat.Event) *ChanClient {
if ch == nil {
ch = make(chan beat.Event, 1)
}
c := &ChanClient{
done: make(chan struct{}),
Channel: ch,
}
return c
}
func (c *ChanClient) Close() error {
close(c.done)
return nil
}
// PublishEvent will publish the event on the channel. Options will be ignored.
// Always returns true.
func (c *ChanClient) Publish(event beat.Event) {
select {
case <-c.done:
case c.Channel <- event:
}
}
func (c *ChanClient) PublishAll(event []beat.Event) {
for _, e := range event {
c.Publish(e)
}
}
func (c *ChanClient) ReceiveEvent() beat.Event {
return <-c.Channel
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v6.0.0-beta2

搜索帮助

0d507c66 1850385 C8b1a773 1850385