本文整理匯總了Golang中github.com/elastic/beats/libbeat/common.Config.SetString方法的典型用法代碼示例。如果您正苦於以下問題:Golang Config.SetString方法的具體用法?Golang Config.SetString怎麽用?Golang Config.SetString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/elastic/beats/libbeat/common.Config
的用法示例。
在下文中一共展示了Config.SetString方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: new
func new(beatName string, cfg *common.Config, _ int) (outputs.Outputer, error) {
if !cfg.HasField("index") {
cfg.SetString("index", -1, beatName)
}
output := &logstash{}
if err := output.init(cfg); err != nil {
return nil, err
}
return output, nil
}
示例2: New
// New instantiates a new output plugin instance publishing to elasticsearch.
func New(beatName string, cfg *common.Config, topologyExpire int) (outputs.Outputer, error) {
if !cfg.HasField("bulk_max_size") {
cfg.SetInt("bulk_max_size", -1, defaultBulkSize)
}
if !cfg.HasField("index") {
pattern := fmt.Sprintf("%v-%%{+yyyy.MM.dd}", beatName)
cfg.SetString("index", -1, pattern)
}
output := &elasticsearchOutput{beatName: beatName}
err := output.init(cfg, topologyExpire)
if err != nil {
return nil, err
}
return output, nil
}
示例3: init
func (r *redisOut) init(cfg *common.Config, expireTopo int) error {
config := defaultConfig
if err := cfg.Unpack(&config); err != nil {
return err
}
sendRetries := config.MaxRetries
maxAttempts := config.MaxRetries + 1
if sendRetries < 0 {
maxAttempts = 0
}
var dataType redisDataType
switch config.DataType {
case "", "list":
dataType = redisListType
case "channel":
dataType = redisChannelType
default:
return errors.New("Bad Redis data type")
}
if cfg.HasField("index") && !cfg.HasField("key") {
s, err := cfg.String("index", -1)
if err != nil {
return err
}
if err := cfg.SetString("key", -1, s); err != nil {
return err
}
}
if !cfg.HasField("key") {
cfg.SetString("key", -1, r.beatName)
}
key, err := outil.BuildSelectorFromConfig(cfg, outil.Settings{
Key: "key",
MultiKey: "keys",
EnableSingleOnly: true,
FailEmpty: true,
})
if err != nil {
return err
}
tls, err := outputs.LoadTLSConfig(config.TLS)
if err != nil {
return err
}
transp := &transport.Config{
Timeout: config.Timeout,
Proxy: &config.Proxy,
TLS: tls,
Stats: &transport.IOStats{
Read: statReadBytes,
Write: statWriteBytes,
ReadErrors: statReadErrors,
WriteErrors: statWriteErrors,
},
}
// configure topology support
r.topology.init(transp, topoConfig{
host: config.HostTopology,
password: config.PasswordTopology,
db: config.DbTopology,
expire: time.Duration(expireTopo) * time.Second,
})
// configure publisher clients
clients, err := modeutil.MakeClients(cfg, func(host string) (mode.ProtocolClient, error) {
t, err := transport.NewClient(transp, "tcp", host, config.Port)
if err != nil {
return nil, err
}
return newClient(t, config.Password, config.Db, key, dataType), nil
})
if err != nil {
return err
}
logp.Info("Max Retries set to: %v", sendRetries)
m, err := modeutil.NewConnectionMode(clients, modeutil.Settings{
Failover: !config.LoadBalance,
MaxAttempts: maxAttempts,
Timeout: config.Timeout,
WaitRetry: defaultWaitRetry,
MaxWaitRetry: defaultMaxWaitRetry,
})
if err != nil {
return err
}
r.mode = m
return nil
}