當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Config.Unpack方法代碼示例

本文整理匯總了Golang中github.com/elastic/beats/libbeat/common.Config.Unpack方法的典型用法代碼示例。如果您正苦於以下問題:Golang Config.Unpack方法的具體用法?Golang Config.Unpack怎麽用?Golang Config.Unpack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/elastic/beats/libbeat/common.Config的用法示例。


在下文中一共展示了Config.Unpack方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: newIncludeFields

func newIncludeFields(c common.Config) (processors.Processor, error) {
	config := struct {
		Fields []string `config:"fields"`
	}{}
	err := c.Unpack(&config)
	if err != nil {
		return nil, fmt.Errorf("fail to unpack the include_fields configuration: %s", err)
	}

	/* add read only fields if they are not yet */
	for _, readOnly := range processors.MandatoryExportedFields {
		found := false
		for _, field := range config.Fields {
			if readOnly == field {
				found = true
			}
		}
		if !found {
			config.Fields = append(config.Fields, readOnly)
		}
	}

	f := includeFields{Fields: config.Fields}
	return &f, nil
}
開發者ID:Zhoutall,項目名稱:beats,代碼行數:25,代碼來源:include_fields.go

示例2: NewHarvester

func NewHarvester(
	cfg *common.Config,
	state file.State,
	prospectorChan chan *input.Event,
	done chan struct{},
) (*Harvester, error) {

	h := &Harvester{
		config:         defaultConfig,
		state:          state,
		prospectorChan: prospectorChan,
		done:           done,
	}

	if err := cfg.Unpack(&h.config); err != nil {
		return nil, err
	}

	encodingFactory, ok := encoding.FindEncoding(h.config.Encoding)
	if !ok || encodingFactory == nil {
		return nil, fmt.Errorf("unknown encoding('%v')", h.config.Encoding)
	}
	h.encodingFactory = encodingFactory

	return h, nil
}
開發者ID:cyrilleverrier,項目名稱:beats,代碼行數:26,代碼來源:harvester.go

示例3: cfgRoundRobinPartitioner

func cfgRoundRobinPartitioner(config *common.Config) (func() partitioner, error) {
	cfg := struct {
		GroupEvents int `config:"group_events" validate:"min=1"`
	}{
		GroupEvents: 1,
	}
	if err := config.Unpack(&cfg); err != nil {
		return nil, err
	}

	return func() partitioner {
		N := cfg.GroupEvents
		count := N
		partition := rand.Int31()

		return func(_ *message, numPartitions int32) (int32, error) {
			if N == count {
				count = 0
				if partition++; partition >= numPartitions {
					partition = 0
				}
			}
			count++
			return partition, nil
		}
	}, nil
}
開發者ID:Zhoutall,項目名稱:beats,代碼行數:27,代碼來源:partition.go

示例4: init

func (k *kafka) init(cfg *common.Config) error {
	debugf("initialize kafka output")

	k.config = defaultConfig
	if err := cfg.Unpack(&k.config); err != nil {
		return err
	}

	var err error
	k.topic, err = outil.BuildSelectorFromConfig(cfg, outil.Settings{
		Key:              "topic",
		MultiKey:         "topics",
		EnableSingleOnly: true,
		FailEmpty:        true,
	})
	if err != nil {
		return err
	}

	_, err = newKafkaConfig(&k.config)
	if err != nil {
		return err
	}

	return nil
}
開發者ID:cyrilleverrier,項目名稱:beats,代碼行數:26,代碼來源:kafka.go

示例5: New

func New(b *beat.Beat, cfg *common.Config) (beat.Beater, error) {
	config := config.DefaultConfig
	if err := cfg.Unpack(&config); err != nil {
		return nil, fmt.Errorf("Error reading config file: %v", err)
	}

	limit := config.Scheduler.Limit
	locationName := config.Scheduler.Location
	if locationName == "" {
		locationName = "Local"
	}
	location, err := time.LoadLocation(locationName)
	if err != nil {
		return nil, err
	}

	client := b.Publisher.Connect()
	sched := scheduler.NewWithLocation(limit, location)
	manager, err := newMonitorManager(client, sched, monitors.Registry, config.Monitors)
	if err != nil {
		return nil, err
	}

	bt := &Heartbeat{
		done:      make(chan struct{}),
		client:    client,
		scheduler: sched,
		manager:   manager,
	}
	return bt, nil
}
開發者ID:andrewkroh,項目名稱:beats,代碼行數:31,代碼來源:heartbeat.go

示例6: init

func (k *kafka) init(cfg *common.Config) error {
	debugf("initialize kafka output")

	config := defaultConfig
	if err := cfg.Unpack(&config); err != nil {
		return err
	}

	topic, err := outil.BuildSelectorFromConfig(cfg, outil.Settings{
		Key:              "topic",
		MultiKey:         "topics",
		EnableSingleOnly: true,
		FailEmpty:        true,
	})
	if err != nil {
		return err
	}

	partitioner, err := makePartitioner(config.Partition)
	if err != nil {
		return err
	}

	k.config = config
	k.partitioner = partitioner
	k.topic = topic

	// validate config one more time
	_, err = k.newKafkaConfig()
	if err != nil {
		return err
	}

	return nil
}
開發者ID:Zhoutall,項目名稱:beats,代碼行數:35,代碼來源:kafka.go

示例7: init

func (lj *logstash) init(cfg *common.Config) error {
	config := defaultConfig
	if err := cfg.Unpack(&config); 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,
		},
	}

	logp.Info("Max Retries set to: %v", config.MaxRetries)
	m, err := initConnectionMode(cfg, &config, transp)
	if err != nil {
		return err
	}

	lj.mode = m
	lj.index = config.Index

	return nil
}
開發者ID:YaSuenag,項目名稱:hsbeat,代碼行數:34,代碼來源:logstash.go

示例8: New

func New(b *beat.Beat, rawConfig *common.Config) (beat.Beater, error) {
	config := config.Config{
		Interfaces: config.InterfacesConfig{
			File:       *cmdLineArgs.file,
			Loop:       *cmdLineArgs.loop,
			TopSpeed:   *cmdLineArgs.topSpeed,
			OneAtATime: *cmdLineArgs.oneAtAtime,
			Dumpfile:   *cmdLineArgs.dumpfile,
		},
	}
	err := rawConfig.Unpack(&config)
	if err != nil {
		logp.Err("fails to read the beat config: %v, %v", err, config)
		return nil, err
	}

	pb := &packetbeat{
		config:      config,
		cmdLineArgs: cmdLineArgs,
	}
	err = pb.init(b)
	if err != nil {
		return nil, err
	}

	return pb, nil
}
開發者ID:ruflin,項目名稱:beats,代碼行數:27,代碼來源:packetbeat.go

示例9: cfgRandomPartitioner

func cfgRandomPartitioner(config *common.Config) (func() partitioner, error) {
	cfg := struct {
		GroupEvents int `config:"group_events" validate:"min=1"`
	}{
		GroupEvents: 1,
	}
	if err := config.Unpack(&cfg); err != nil {
		return nil, err
	}

	return func() partitioner {
		generator := rand.New(rand.NewSource(rand.Int63()))
		N := cfg.GroupEvents
		count := cfg.GroupEvents
		partition := int32(0)

		return func(_ *message, numPartitions int32) (int32, error) {
			if N == count {
				count = 0
				partition = int32(generator.Intn(int(numPartitions)))
			}
			count++
			return partition, nil
		}
	}, nil
}
開發者ID:Zhoutall,項目名稱:beats,代碼行數:26,代碼來源:partition.go

示例10: ReadHostList

func ReadHostList(cfg *common.Config) ([]string, error) {
	config := struct {
		Hosts  []string `config:"hosts"`
		Worker int      `config:"worker"`
	}{
		Worker: 1,
	}

	err := cfg.Unpack(&config)
	if err != nil {
		return nil, err
	}

	lst := config.Hosts
	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:ChongFeng,項目名稱:beats,代碼行數:28,代碼來源:modeutil.go

示例11: NewModule

// NewModule creates a new module
func NewModule(cfg *common.Config, moduler func() Moduler) (*Module, error) {

	// Module config defaults
	config := ModuleConfig{
		Period:  "1s",
		Enabled: true,
	}

	err := cfg.Unpack(&config)
	if err != nil {
		return nil, err
	}

	filters, err := filter.New(config.Filters)
	if err != nil {
		return nil, fmt.Errorf("error initializing filters: %v", err)
	}
	logp.Debug("module", "Filters: %+v", filters)

	return &Module{
		name:       config.Module,
		Config:     config,
		cfg:        cfg,
		moduler:    moduler(),
		metricSets: map[string]*MetricSet{},
		Publish:    make(chan common.MapStr), // TODO: What should be size of channel? @ruflin,20160316
		wg:         sync.WaitGroup{},
		done:       make(chan struct{}),
		filters:    filters,
	}, nil
}
開發者ID:radoondas,項目名稱:apachebeat,代碼行數:32,代碼來源:module.go

示例12: newDropFields

func newDropFields(c common.Config) (filter.FilterRule, error) {

	f := DropFields{}

	if err := f.CheckConfig(c); err != nil {
		return nil, err
	}

	config := DropFieldsConfig{}

	err := c.Unpack(&config)
	if err != nil {
		return nil, fmt.Errorf("fail to unpack the drop_fields configuration: %s", err)
	}

	/* remove read only fields */
	for _, readOnly := range filter.MandatoryExportedFields {
		for i, field := range config.Fields {
			if readOnly == field {
				config.Fields = append(config.Fields[:i], config.Fields[i+1:]...)
			}
		}
	}
	f.Fields = config.Fields

	cond, err := filter.NewCondition(config.ConditionConfig)
	if err != nil {
		return nil, err
	}
	f.Cond = cond

	return &f, nil
}
開發者ID:mheese,項目名稱:journalbeat,代碼行數:33,代碼來源:drop_fields.go

示例13: New

// Creates beater
func New(b *beat.Beat, rawConfig *common.Config) (beat.Beater, error) {
	cfg := config.DefaultConfig
	err := rawConfig.Unpack(&cfg)
	if err != nil {
		return nil, fmt.Errorf("Error reading config file: %v", err)
	}

	done := make(chan struct{})

	workers := []*worker{}
	for name, cfg := range cfg.Generators {
		factory, ok := generators[name]
		if !ok {
			return nil, fmt.Errorf("Unknown generator: %v", name)
		}

		generators, err := factory(cfg)
		if err != nil {
			return nil, err
		}

		for _, gen := range generators {
			workers = append(workers, &worker{
				done: done,
				gen:  gen,
			})
		}
	}

	return &Generatorbeat{
		done:   done,
		worker: workers,
	}, nil
}
開發者ID:urso,項目名稱:generatorbeat,代碼行數:35,代碼來源:generatorbeat.go

示例14: New

func New(config *common.Config, _ int) (outputs.Outputer, error) {
	c := &console{config: defaultConfig}
	err := config.Unpack(&c.config)
	if err != nil {
		return nil, err
	}
	return c, nil
}
開發者ID:mheese,項目名稱:journalbeat,代碼行數:8,代碼來源:console.go

示例15: newBaseModuleFromConfig

// newBaseModuleFromConfig creates a new BaseModule from config.
func newBaseModuleFromConfig(rawConfig *common.Config) (BaseModule, error) {
	baseModule := BaseModule{
		config:    defaultModuleConfig,
		rawConfig: rawConfig,
	}
	err := rawConfig.Unpack(&baseModule.config)
	baseModule.name = strings.ToLower(baseModule.config.Module)
	return baseModule, err
}
開發者ID:yan2jared,項目名稱:beats,代碼行數:10,代碼來源:builders.go


注:本文中的github.com/elastic/beats/libbeat/common.Config.Unpack方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。