本文整理汇总了Golang中github.com/urso/ucfg.Config类的典型用法代码示例。如果您正苦于以下问题:Golang Config类的具体用法?Golang Config怎么用?Golang Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: New
func New(config *ucfg.Config, _ int) (outputs.Outputer, error) {
c := &console{config: defaultConfig}
err := config.Unpack(&c.config)
if err != nil {
return nil, err
}
return c, nil
}
开发者ID:jarpy,项目名称:beats,代码行数:8,代码来源:console.go
示例2: init
func (k *kafka) init(cfg *ucfg.Config) error {
debugf("initialize kafka output")
config := defaultConfig
if err := cfg.Unpack(&config); err != nil {
return err
}
libCfg, retries, err := newKafkaConfig(&config)
if err != nil {
return err
}
hosts := config.Hosts
if len(hosts) < 1 {
logp.Err("Kafka configuration failed with: %v", errNoHosts)
return errNoHosts
}
debugf("hosts: %v", hosts)
useType := config.UseType
topic := config.Topic
if topic == "" && !useType {
logp.Err("Kafka configuration failed with: %v", errNoTopicSet)
return errNoTopicSet
}
var clients []mode.AsyncProtocolClient
worker := 1
if config.Worker > 1 {
worker = config.Worker
}
for i := 0; i < worker; i++ {
client, err := newKafkaClient(hosts, topic, useType, libCfg)
if err != nil {
logp.Err("Failed to create kafka client: %v", err)
return err
}
clients = append(clients, client)
}
mode, err := mode.NewAsyncConnectionMode(
clients,
false,
retries, // retry implemented by kafka client
libCfg.Producer.Retry.Backoff,
libCfg.Net.WriteTimeout,
10*time.Second)
if err != nil {
logp.Err("Failed to configure kafka connection: %v", err)
return err
}
k.mode = mode
return nil
}
开发者ID:jarpy,项目名称:beats,代码行数:58,代码来源:kafka.go
示例3: New
// NewOutput instantiates a new output plugin instance publishing to elasticsearch.
func New(cfg *ucfg.Config, topologyExpire int) (outputs.Outputer, error) {
if !cfg.HasField("bulk_max_size") {
cfg.SetInt("bulk_max_size", 0, defaultBulkSize)
}
output := &elasticsearchOutput{}
err := output.init(cfg, topologyExpire)
if err != nil {
return nil, err
}
return output, nil
}
开发者ID:jarpy,项目名称:beats,代码行数:13,代码来源:output.go
示例4: New
func New(cfg *ucfg.Config, topologyExpire int) (outputs.Outputer, error) {
config := defaultConfig
if err := cfg.Unpack(&config); err != nil {
return nil, err
}
output := &redisOutput{}
if err := output.Init(&config, topologyExpire); err != nil {
return nil, err
}
return output, nil
}
开发者ID:jarpy,项目名称:beats,代码行数:12,代码来源:redis.go
示例5: New
func New(testMode bool, results publish.Transactions, cfg *ucfg.Config) (*Icmp, error) {
p := &Icmp{}
config := defaultConfig
if !testMode {
if err := cfg.Unpack(&config); err != nil {
return nil, err
}
}
if err := p.init(results, &config); err != nil {
return nil, err
}
return p, nil
}
开发者ID:jarpy,项目名称:beats,代码行数:14,代码来源:icmp.go
示例6: init
func (lj *logstash) init(cfg *ucfg.Config) error {
config := defaultConfig
if err := cfg.Unpack(&config); err != nil {
return err
}
useTLS := (config.TLS != nil)
timeout := time.Duration(config.Timeout) * time.Second
sendRetries := config.MaxRetries
maxAttempts := sendRetries + 1
if sendRetries < 0 {
maxAttempts = 0
}
var clients []mode.ProtocolClient
var err error
if useTLS {
var tlsConfig *tls.Config
tlsConfig, err = outputs.LoadTLSConfig(config.TLS)
if err != nil {
return err
}
clients, err = mode.MakeClients(cfg,
makeClientFactory(&config, makeTLSClient(config.Port, tlsConfig)))
} else {
clients, err = mode.MakeClients(cfg,
makeClientFactory(&config, makeTCPClient(config.Port)))
}
if err != nil {
return err
}
logp.Info("Max Retries set to: %v", sendRetries)
m, err := mode.NewConnectionMode(clients, !config.LoadBalance,
maxAttempts, waitRetry, timeout, maxWaitRetry)
if err != nil {
return err
}
lj.mode = m
lj.index = config.Index
return nil
}
开发者ID:jarpy,项目名称:beats,代码行数:45,代码来源:logstash.go
示例7: New
func New(
testMode bool,
results publish.Transactions,
cfg *ucfg.Config,
) (protos.Plugin, error) {
p := &Thrift{}
config := defaultConfig
if !testMode {
if err := cfg.Unpack(&config); err != nil {
return nil, err
}
}
if err := p.init(testMode, results, &config); err != nil {
return nil, err
}
return p, nil
}
开发者ID:jarpy,项目名称:beats,代码行数:18,代码来源:thrift.go
示例8: newOutputWorker
func newOutputWorker(
cfg *ucfg.Config,
out outputs.Outputer,
ws *common.WorkerSignal,
hwm int,
bulkHWM int,
) *outputWorker {
config := defaultConfig
err := cfg.Unpack(&config)
if err != nil {
logp.Err("Failed to read output worker config: %v", err)
return nil
}
o := &outputWorker{
out: outputs.CastBulkOutputer(out),
config: config,
maxBulkSize: config.BulkMaxSize,
}
o.messageWorker.init(ws, hwm, bulkHWM, o)
return o
}
开发者ID:jarpy,项目名称:beats,代码行数:22,代码来源:output.go
示例9: ReadHostList
func ReadHostList(cfg *ucfg.Config) ([]string, error) {
config := struct {
Host string `config:"host"`
Hosts []string `config:"hosts"`
Worker int `config:"worker"`
}{
Worker: 1,
}
err := cfg.Unpack(&config)
if err != nil {
return nil, err
}
// TODO: remove config.Host
var lst []string
if len(config.Hosts) > 0 {
lst = config.Hosts
} else if config.Host != "" {
lst = []string{config.Host}
}
if len(lst) == 0 || config.Worker <= 1 {
return lst, nil
}
// duplicate entries config.Workers times
hosts := make([]string, 0, len(lst)*config.Worker)
for _, entry := range lst {
for i := 0; i < config.Worker; i++ {
hosts = append(hosts, entry)
}
}
return hosts, nil
}
开发者ID:jarpy,项目名称:beats,代码行数:36,代码来源:mode.go
示例10: New
func New(cfg *ucfg.Config, _ int) (outputs.Outputer, error) {
config := defaultConfig
if err := cfg.Unpack(&config); err != nil {
return nil, err
}
// disable bulk support in publisher pipeline
cfg.SetInt("flush_interval", 0, -1)
cfg.SetInt("bulk_max_size", 0, -1)
output := &fileOutput{}
if err := output.init(config); err != nil {
return nil, err
}
return output, nil
}
开发者ID:jarpy,项目名称:beats,代码行数:16,代码来源:file.go
示例11: init
func (out *elasticsearchOutput) init(
cfg *ucfg.Config,
topologyExpire int,
) error {
config := defaultConfig
if err := cfg.Unpack(&config); err != nil {
return err
}
tlsConfig, err := outputs.LoadTLSConfig(config.TLS)
if err != nil {
return err
}
clients, err := mode.MakeClients(cfg, makeClientFactory(tlsConfig, &config))
if err != nil {
return err
}
timeout := time.Duration(config.Timeout) * time.Second
maxRetries := config.MaxRetries
maxAttempts := maxRetries + 1 // maximum number of send attempts (-1 = infinite)
if maxRetries < 0 {
maxAttempts = 0
}
var waitRetry = time.Duration(1) * time.Second
var maxWaitRetry = time.Duration(60) * time.Second
out.clients = clients
loadBalance := config.LoadBalance
m, err := mode.NewConnectionMode(clients, !loadBalance,
maxAttempts, waitRetry, timeout, maxWaitRetry)
if err != nil {
return err
}
loadTemplate(config.Template, clients)
if config.SaveTopology {
err := out.EnableTTL()
if err != nil {
logp.Err("Fail to set _ttl mapping: %s", err)
// keep trying in the background
go func() {
for {
err := out.EnableTTL()
if err == nil {
break
}
logp.Err("Fail to set _ttl mapping: %s", err)
time.Sleep(5 * time.Second)
}
}()
}
}
out.TopologyExpire = 15000
if topologyExpire != 0 {
out.TopologyExpire = topologyExpire * 1000 // millisec
}
out.mode = m
out.index = config.Index
return nil
}
开发者ID:jarpy,项目名称:beats,代码行数:68,代码来源:output.go
注:本文中的github.com/urso/ucfg.Config类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论