代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。