代码拉取完成,页面将自动刷新
package autodiscover
import (
"fmt"
"strings"
"sync"
"github.com/elastic/beats/libbeat/cfgfile"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/bus"
"github.com/elastic/beats/libbeat/logp"
)
// Provider for autodiscover
type Provider interface {
cfgfile.Runner
}
// ProviderRegistry holds all known autodiscover providers, they must be added to it to enable them for use
var ProviderRegistry = NewRegistry()
// ProviderBuilder creates a new provider based on the given config and returns it
type ProviderBuilder func(bus.Bus, *common.Config) (Provider, error)
// Register of autodiscover providers
type registry struct {
// Lock to control concurrent read/writes
lock sync.RWMutex
// A map of provider name to ProviderBuilder.
providers map[string]ProviderBuilder
}
// NewRegistry creates and returns a new Registry
func NewRegistry() *registry {
return ®istry{
providers: make(map[string]ProviderBuilder, 0),
}
}
// AddProvider registers a new ProviderBuilder
func (r *registry) AddProvider(name string, provider ProviderBuilder) error {
r.lock.Lock()
defer r.lock.Unlock()
if name == "" {
return fmt.Errorf("provider name is required")
}
_, exists := r.providers[name]
if exists {
return fmt.Errorf("provider '%s' is already registered", name)
}
if provider == nil {
return fmt.Errorf("provider '%s' cannot be registered with a nil factory", name)
}
r.providers[name] = provider
logp.Debug(debugK, "Provider registered: %s", name)
return nil
}
// GetProvider returns the provider with the giving name, nil if it doesn't exist
func (r *registry) GetProvider(name string) ProviderBuilder {
r.lock.RLock()
defer r.lock.RUnlock()
name = strings.ToLower(name)
return r.providers[name]
}
// BuildProvider reads provider configuration and instatiate one
func (r *registry) BuildProvider(bus bus.Bus, c *common.Config) (Provider, error) {
var config ProviderConfig
err := c.Unpack(&config)
if err != nil {
return nil, err
}
builder := r.GetProvider(config.Type)
if builder == nil {
return nil, fmt.Errorf("Unknown autodiscover provider %s", config.Type)
}
return builder(bus, c)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。