代码拉取完成,页面将自动刷新
package dialchain
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/outputs/transport"
)
// DialerChain composes builders for multiple network layers, used to build
// the final transport.Dialer object based on the network layers.
// Each layer can hold individual configurations. Use 'Clone' to copy and replace/wrap
// layers at will.
// Once all Layers have been prepared, use Build to build a transport.Dialer that can
// used with any go library network packages relying on standard library based dialers.
//
// For Additional Layering capabilities, DialerChain implements the NetDialer interface.
type DialerChain struct {
Net NetDialer
Layers []Layer
}
// NetDialer provides the most low-level network layer for setting up a network
// connection. NetDialer objects do not support wrapping any lower network layers.
type NetDialer func(common.MapStr) (transport.Dialer, error)
// Layer is a configured network layer, wrapping any lower-level network layers.
type Layer func(common.MapStr, transport.Dialer) (transport.Dialer, error)
// Clone create a shallow copy of c.
func (c *DialerChain) Clone() *DialerChain {
d := &DialerChain{
Net: c.Net,
Layers: make([]Layer, len(c.Layers)),
}
copy(d.Layers, c.Layers)
return d
}
// Build create a new transport.Dialer for use with other networking libraries.
func (c *DialerChain) Build(event common.MapStr) (d transport.Dialer, err error) {
d, err = c.Net.build(event)
if err != nil {
return
}
for _, layer := range c.Layers {
if d, err = layer.build(event, d); err != nil {
return nil, err
}
}
return
}
// AddLayer adds another layer to the dialer chain.
// The layer being added is the new topmost network layer using the other
// already present layers on dial.
func (c *DialerChain) AddLayer(l Layer) {
c.Layers = append(c.Layers, l)
}
// TestBuild tries to build the DialerChain and reports any error reported by
// one of the layers.
func (c *DialerChain) TestBuild() error {
_, err := c.Build(common.MapStr{})
return err
}
func (d NetDialer) build(event common.MapStr) (transport.Dialer, error) {
return d(event)
}
func (l Layer) build(event common.MapStr, next transport.Dialer) (transport.Dialer, error) {
return l(event, next)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。