• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang toml.DecodeFile函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/bbangert/toml.DecodeFile函数的典型用法代码示例。如果您正苦于以下问题:Golang DecodeFile函数的具体用法?Golang DecodeFile怎么用?Golang DecodeFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了DecodeFile函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: LoadHekadConfig

func LoadHekadConfig(configPath string) (config *HekadConfig, err error) {
	idle, _ := time.ParseDuration("2m")

	config = &HekadConfig{Maxprocs: 1,
		PoolSize:              100,
		DecoderPoolSize:       4,
		ChanSize:              50,
		CpuProfName:           "",
		MemProfName:           "",
		MaxMsgLoops:           4,
		MaxMsgProcessInject:   1,
		MaxMsgProcessDuration: 100000,
		MaxMsgTimerInject:     10,
		MaxPackIdle:           idle,
		BaseDir:               filepath.FromSlash("/var/cache/hekad"),
		ShareDir:              filepath.FromSlash("/usr/share/heka"),
	}

	var configFile map[string]toml.Primitive
	p, err := os.Open(configPath)
	if err != nil {
		return nil, fmt.Errorf("Error opening config file: %s", err)
	}
	fi, err := p.Stat()
	if err != nil {
		return nil, fmt.Errorf("Error fetching config file info: %s", err)
	}

	if fi.IsDir() {
		files, _ := ioutil.ReadDir(configPath)
		for _, f := range files {
			fName := f.Name()
			if strings.HasPrefix(fName, ".") || strings.HasSuffix(fName, ".bak") ||
				strings.HasSuffix(fName, ".tmp") || strings.HasSuffix(fName, "~") {
				// Skip obviously non-relevant files.
				continue
			}
			fPath := filepath.Join(configPath, fName)
			if _, err = toml.DecodeFile(fPath, &configFile); err != nil {
				return nil, fmt.Errorf("Error decoding config file: %s", err)
			}
		}
	} else {
		if _, err = toml.DecodeFile(configPath, &configFile); err != nil {
			return nil, fmt.Errorf("Error decoding config file: %s", err)
		}
	}

	empty_ignore := map[string]interface{}{}
	parsed_config, ok := configFile["hekad"]
	if ok {
		if err = toml.PrimitiveDecodeStrict(parsed_config, config, empty_ignore); err != nil {
			err = fmt.Errorf("Can't unmarshal config: %s", err)
		}
	}

	return
}
开发者ID:Jimdo,项目名称:heka,代码行数:58,代码来源:config.go


示例2: main

func main() {
	configFile := flag.String("config", "logstreamer.toml", "Heka Logstreamer configuration file")

	flag.Parse()

	if flag.NFlag() == 0 {
		flag.PrintDefaults()
		os.Exit(0)
	}

	p, err := os.Open(*configFile)
	if err != nil {
		client.LogError.Fatalf("Error opening config file: %s", err)
	}
	fi, err := p.Stat()
	if err != nil {
		client.LogError.Fatalf("Error fetching config file info: %s", err)
	}

	fconfig := make(FileConfig)
	if fi.IsDir() {
		files, _ := ioutil.ReadDir(*configFile)
		for _, f := range files {
			fName := f.Name()
			if strings.HasPrefix(fName, ".") || strings.HasSuffix(fName, ".bak") ||
				strings.HasSuffix(fName, ".tmp") || strings.HasSuffix(fName, "~") {
				// Skip obviously non-relevant files.
				continue
			}
			fPath := filepath.Join(*configFile, fName)
			if _, err = toml.DecodeFile(fPath, &fconfig); err != nil {
				client.LogError.Fatalf("Error decoding config file: %s", err)
			}
		}
	} else {
		if _, err := toml.DecodeFile(*configFile, &fconfig); err != nil {
			client.LogError.Fatalf("Error decoding config file: %s", err)
		}
	}

	// Filter out logstream inputs
	inputs := make(map[string]toml.Primitive)
	for name, prim := range fconfig {
		basic := new(Basic)
		if name == "LogstreamerInput" {
			inputs[name] = prim
		} else if err := toml.PrimitiveDecode(prim, &basic); err == nil {
			if basic.PluginType == "LogstreamerInput" {
				inputs[name] = prim
			}
		}
	}

	// Go through the logstreams and parse their configs
	for name, prim := range inputs {
		parseConfig(name, prim)
	}
}
开发者ID:orangemi,项目名称:heka,代码行数:58,代码来源:main.go


示例3: main

func main() {
	configFile := flag.String("config", "logstreamer.toml", "Heka Logstreamer configuration file")

	flag.Parse()

	if flag.NFlag() == 0 {
		flag.PrintDefaults()
		os.Exit(0)
	}

	fconfig := make(FileConfig)
	if _, err := toml.DecodeFile(*configFile, &fconfig); err != nil {
		log.Printf("Error decoding config file: %s", err)
		return
	}

	// Filter out logstream inputs
	inputs := make(map[string]toml.Primitive)
	for name, prim := range fconfig {
		basic := new(Basic)
		if name == "LogstreamerInput" {
			inputs[name] = prim
		} else if err := toml.PrimitiveDecode(prim, &basic); err == nil {
			if basic.PluginType == "LogstreamerInput" {
				inputs[name] = prim
			}
		}
	}

	// Go through the logstreams and parse their configs
	for name, prim := range inputs {
		parseConfig(name, prim)
	}
}
开发者ID:CodeSummer,项目名称:heka,代码行数:34,代码来源:main.go


示例4: loadProcessFile

func (pdi *ProcessDirectoryInput) loadProcessFile(path string) (*ProcessEntry, error) {
	var err error
	unparsedConfig := make(map[string]toml.Primitive)
	if _, err = toml.DecodeFile(path, &unparsedConfig); err != nil {
		return nil, err
	}
	section, ok := unparsedConfig["ProcessInput"]
	if !ok {
		err = errors.New("No `ProcessInput` section.")
		return nil, err
	}

	maker, err := NewPluginMaker("ProcessInput", pdi.pConfig, section)
	if err != nil {
		return nil, fmt.Errorf("can't create plugin maker: %s", err)
	}

	mutMaker := maker.(MutableMaker)
	mutMaker.SetName(path)
	if err = mutMaker.PrepConfig(); err != nil {
		return nil, fmt.Errorf("can't prep config: %s", err)
	}

	entry := &ProcessEntry{
		maker:  mutMaker,
		config: mutMaker.Config().(*ProcessInputConfig),
	}
	return entry, nil
}
开发者ID:orangemi,项目名称:heka,代码行数:29,代码来源:process_directory_input.go


示例5: restoreSandboxes

// On Heka restarts this function reloads all previously running SandboxFilters
// using the script, configuration, and preservation files in the working
// directory.
func (this *SandboxManagerFilter) restoreSandboxes(fr pipeline.FilterRunner, h pipeline.PluginHelper, dir string) {
	glob := fmt.Sprintf("%s-*.toml", getNormalizedName(fr.Name()))
	if matches, err := filepath.Glob(filepath.Join(dir, glob)); err == nil {
		for _, fn := range matches {
			var configFile pipeline.ConfigFile
			if _, err = toml.DecodeFile(fn, &configFile); err != nil {
				fr.LogError(fmt.Errorf("restoreSandboxes failed: %s\n", err))
				continue
			} else {
				for _, conf := range configFile {
					var runner pipeline.FilterRunner
					name := path.Base(fn[:len(fn)-5])
					fr.LogMessage(fmt.Sprintf("Loading: %s", name))
					runner, err = this.createRunner(dir, name, conf)
					if err != nil {
						fr.LogError(fmt.Errorf("createRunner failed: %s\n", err.Error()))
						removeAll(dir, fmt.Sprintf("%s.*", name))
						break
					}
					err = h.PipelineConfig().AddFilterRunner(runner)
					if err != nil {
						fr.LogError(err)
					} else {
						atomic.AddInt32(&this.currentFilters, 1)
					}
					break // only interested in the first item
				}
			}
		}
	}
}
开发者ID:Huangyan9188,项目名称:heka,代码行数:34,代码来源:sandbox_manager_filter.go


示例6: LoadFromConfigFile

// LoadFromConfigFile loads a TOML configuration file and stores the
// result in the value pointed to by config. The maps in the config
// will be initialized as needed.
//
// The PipelineConfig should be already initialized before passed in via
// its Init function.
func (self *PipelineConfig) LoadFromConfigFile(filename string) (err error) {
	var configFile ConfigFile
	if _, err = toml.DecodeFile(filename, &configFile); err != nil {
		return fmt.Errorf("Error decoding config file: %s", err)
	}

	// Load all the plugins
	var errcnt uint
	for name, conf := range configFile {
		if name == "hekad" {
			continue
		}
		log.Printf("Loading: [%s]\n", name)
		errcnt += self.loadSection(name, conf)
	}

	// Add JSON/PROTOCOL_BUFFER decoders if none were configured
	var configDefault ConfigFile
	toml.Decode(defaultDecoderTOML, &configDefault)
	dWrappers := self.DecoderWrappers

	if _, ok := dWrappers["ProtobufDecoder"]; !ok {
		log.Println("Loading: [ProtobufDecoder]")
		errcnt += self.loadSection("ProtobufDecoder", configDefault["ProtobufDecoder"])
	}

	if errcnt != 0 {
		return fmt.Errorf("%d errors loading plugins", errcnt)
	}

	return
}
开发者ID:KushalP,项目名称:heka,代码行数:38,代码来源:config.go


示例7: LoadHekadConfig

func LoadHekadConfig(filename string) (config *HekadConfig, err error) {
	config = &HekadConfig{Maxprocs: 1,
		PoolSize:            100,
		DecoderPoolSize:     4,
		ChanSize:            50,
		CpuProfName:         "",
		MemProfName:         "",
		MaxMsgLoops:         4,
		MaxMsgProcessInject: 1,
		MaxMsgTimerInject:   10,
	}

	var configFile map[string]toml.Primitive

	if _, err = toml.DecodeFile(filename, &configFile); err != nil {
		return nil, fmt.Errorf("Error decoding config file: %s", err)
	}

	empty_ignore := map[string]interface{}{}
	parsed_config, ok := configFile["hekad"]
	if ok {
		if err = toml.PrimitiveDecodeStrict(parsed_config, &config, empty_ignore); err != nil {
			err = fmt.Errorf("Can't unmarshal config: %s", err)
		}
	}

	return
}
开发者ID:pchojnacki,项目名称:heka,代码行数:28,代码来源:config.go


示例8: main

func main() {
	configFile := flag.String("config", "sbmgr.toml", "Sandbox manager configuration file")
	scriptFile := flag.String("script", "xyz.lua", "Sandbox script file")
	scriptConfig := flag.String("scriptconfig", "xyz.toml", "Sandbox script configuration file")
	filterName := flag.String("filtername", "filter", "Sandbox filter name (used on unload)")
	action := flag.String("action", "load", "Sandbox manager action")
	flag.Parse()

	var config SbmgrConfig
	if _, err := toml.DecodeFile(*configFile, &config); err != nil {
		log.Printf("Error decoding config file: %s", err)
		return
	}
	sender, err := client.NewNetworkSender("tcp", config.IpAddress)
	if err != nil {
		log.Fatalf("Error creating sender: %s\n", err.Error())
	}
	encoder := client.NewProtobufEncoder(&config.Signer)
	manager := client.NewClient(sender, encoder)

	hostname, _ := os.Hostname()
	msg := &message.Message{}
	msg.SetType("heka.control.sandbox")
	msg.SetTimestamp(time.Now().UnixNano())
	msg.SetUuid(uuid.NewRandom())
	msg.SetHostname(hostname)

	switch *action {
	case "load":
		code, err := ioutil.ReadFile(*scriptFile)
		if err != nil {
			log.Printf("Error reading scriptFile: %s\n", err.Error())
			return
		}
		msg.SetPayload(string(code))
		conf, err := ioutil.ReadFile(*scriptConfig)
		if err != nil {
			log.Printf("Error reading scriptConfig: %s\n", err.Error())
			return
		}
		f, _ := message.NewField("config", string(conf), "toml")
		msg.AddField(f)
	case "unload":
		f, _ := message.NewField("name", *filterName, "")
		msg.AddField(f)
	default:
		log.Printf("Invalid action: %s", *action)
	}

	f1, _ := message.NewField("action", *action, "")
	msg.AddField(f1)
	err = manager.SendMessage(msg)
	if err != nil {
		log.Printf("Error sending message: %s\n", err.Error())
	}
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:56,代码来源:main.go


示例9: LoadApplicationFromFileName

// Handles reading a TOML based configuration file, and loading an
// initialized Application, ready to Run
func LoadApplicationFromFileName(filename string, logging int) (
	app *Application, err error) {

	var configFile ConfigFile
	if _, err = toml.DecodeFile(filename, &configFile); err != nil {
		return nil, fmt.Errorf("Error decoding config file: %s", err)
	}
	env := envconf.Load()
	return LoadApplication(configFile, env, logging)
}
开发者ID:jrconlin,项目名称:pushgo,代码行数:12,代码来源:config.go


示例10: main

func main() {
	var config Config
	config_file := flag.String("config", filepath.FromSlash("/etc/heka-server.toml"), "Config file for log server")

	if _, err := toml.DecodeFile(*config_file, &config); err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(config)
}
开发者ID:wanghe4096,项目名称:golang_demo,代码行数:11,代码来源:main.go


示例11: LoadHeimdallConfig

// LoadHeimdallConfig accepts the path of a configuration file
// to load. Additionally, it configures defaults for values that
// are not specified within the configuration passed.
func LoadHeimdallConfig(path string) (config *Config, err error) {
	config = &Config{CleanupInterval: "3m",
		Port:      ":9001",
		Cert:      "cert.pem",
		Key:       "key.pem",
		Auth:      AuthConfig{DBPath: "/var/cache/heimdall/auth"},
		Blacklist: BlacklistConfig{DBPath: "/var/cache/heimdall/blacklist", Path: "/blacklist/", DefaultTTL: "1h"},
		Whitelist: WhitelistConfig{DBPath: "/var/cache/heimdall/whitelist", Path: "/whitelist/", DefaultTTL: "72h"},
		PanOS:     PanOSConfig{Enabled: false, Path: "/panos/"}}

	if _, err := toml.DecodeFile(path, config); err != nil {
		return nil, fmt.Errorf("Problem decoding configuration file: %s", err)
	}
	return config, nil
}
开发者ID:Battelle,项目名称:heimdall,代码行数:18,代码来源:config.go


示例12: LoadFromConfigFile

// LoadFromConfigFile loads a TOML configuration file and stores the
// result in the value pointed to by config. The maps in the config
// will be initialized as needed.
//
// The PipelineConfig should be already initialized before passed in via
// its Init function.
func (self *PipelineConfig) LoadFromConfigFile(filename string) (err error) {
	var configFile ConfigFile
	if _, err = toml.DecodeFile(filename, &configFile); err != nil {
		return fmt.Errorf("Error decoding config file: %s", err)
	}

	// Load all the plugins
	var errcnt uint
	for name, conf := range configFile {
		log.Println("Loading: ", name)
		errcnt += self.loadSection(name, conf)
	}

	// Add JSON/PROTOCOL_BUFFER decoders if none were configured
	var configDefault ConfigFile
	toml.Decode(defaultDecoderTOML, &configDefault)
	dWrappers := self.DecoderWrappers

	if _, ok := dWrappers["JsonDecoder"]; !ok {
		log.Println("Loading: JsonDecoder")
		errcnt += self.loadSection("JsonDecoder", configDefault["JsonDecoder"])
	}
	if _, ok := dWrappers["ProtobufDecoder"]; !ok {
		log.Println("Loading: ProtobufDecoder")
		errcnt += self.loadSection("ProtobufDecoder", configDefault["ProtobufDecoder"])
	}

	// Create / prep the DecoderSet pool
	var dRunner DecoderRunner
	for i := 0; i < Globals().DecoderPoolSize; i++ {
		if self.DecoderSets[i], err = newDecoderSet(dWrappers); err != nil {
			log.Println(err)
			errcnt += 1
		}
		for _, dRunner = range self.DecoderSets[i].AllByName() {
			dRunner.Start(self, &self.decodersWg)
		}
		self.decodersChan <- self.DecoderSets[i]
	}

	if errcnt != 0 {
		return fmt.Errorf("%d errors loading plugins", errcnt)
	}

	return
}
开发者ID:hellcoderz,项目名称:heka,代码行数:52,代码来源:config.go


示例13: Init

func (this *SandboxManagerFilter) Init(config interface{}) (err error) {
	conf := config.(*SandboxManagerFilterConfig)
	this.maxFilters = conf.MaxFilters
	this.workingDirectory, _ = filepath.Abs(conf.WorkingDirectory)
	if err = os.MkdirAll(this.workingDirectory, 0700); err != nil {
		return err
	}
	filename := path.Join(this.workingDirectory, "config.toml")
	_, err = os.Stat(filename)
	if err == nil {
		var configFile ConfigFile
		if _, err := toml.DecodeFile(filename, &configFile); err != nil {
			return fmt.Errorf("Error decoding config file: %s", err)
		}
	}
	return nil
}
开发者ID:hellcoderz,项目名称:heka,代码行数:17,代码来源:sandbox_manager_filter.go


示例14: loadProcessFile

func (pdi *ProcessDirectoryInput) loadProcessFile(path string) (*ProcessEntry, error) {
	var err error
	unparsedConfig := make(map[string]toml.Primitive)
	if _, err = toml.DecodeFile(path, &unparsedConfig); err != nil {
		return nil, err
	}
	section, ok := unparsedConfig["ProcessInput"]
	if !ok {
		err = errors.New("No `ProcessInput` section.")
		return nil, err
	}

	maker, err := NewPluginMaker("ProcessInput", pdi.pConfig, section)
	if err != nil {
		return nil, fmt.Errorf("can't create plugin maker: %s", err)
	}

	mutMaker := maker.(MutableMaker)
	mutMaker.SetName(path)

	prepCommonTypedConfig := func() (interface{}, error) {
		commonTypedConfig, err := mutMaker.OrigPrepCommonTypedConfig()
		if err != nil {
			return nil, err
		}
		commonInput := commonTypedConfig.(CommonInputConfig)
		commonInput.Retries = RetryOptions{
			MaxDelay:   "30s",
			Delay:      "250ms",
			MaxRetries: -1,
		}
		if commonInput.CanExit == nil {
			b := true
			commonInput.CanExit = &b
		}
		return commonInput, nil
	}
	mutMaker.SetPrepCommonTypedConfig(prepCommonTypedConfig)

	entry := &ProcessEntry{
		maker: mutMaker,
	}
	return entry, nil
}
开发者ID:Nitro,项目名称:heka,代码行数:44,代码来源:process_directory_input.go


示例15: loadProcessFile

func (pdi *ProcessDirectoryInput) loadProcessFile(path string) (config *ProcessInputConfig,
	err error) {

	unparsedConfig := make(map[string]toml.Primitive)
	if _, err = toml.DecodeFile(path, &unparsedConfig); err != nil {
		return
	}
	section, ok := unparsedConfig["ProcessInput"]
	if !ok {
		err = errors.New("No `ProcessInput` section.")
		return
	}
	config = &ProcessInputConfig{
		ParserType:  "token",
		ParseStdout: true,
		Trim:        true,
	}
	if err = toml.PrimitiveDecodeStrict(section, config, nil); err != nil {
		return nil, err
	}
	return
}
开发者ID:RogerBai,项目名称:heka,代码行数:22,代码来源:process_directory_input.go


示例16: main

func main() {
	configFile := flag.String("config", "sbmgr.toml", "Sandbox manager configuration file")
	scriptFile := flag.String("script", "xyz.lua", "Sandbox script file")
	scriptConfig := flag.String("scriptconfig", "xyz.toml", "Sandbox script configuration file")
	filterName := flag.String("filtername", "filter", "Sandbox filter name (used on unload)")
	action := flag.String("action", "load", "Sandbox manager action")
	flag.Parse()

	var config SbmgrConfig
	if _, err := toml.DecodeFile(*configFile, &config); err != nil {
		client.LogError.Printf("Error decoding config file: %s", err)
		return
	}
	var sender *client.NetworkSender
	var err error
	if config.UseTls {
		var goTlsConfig *tls.Config
		goTlsConfig, err = tcp.CreateGoTlsConfig(&config.Tls)
		if err != nil {
			client.LogError.Fatalf("Error creating TLS config: %s\n", err)
		}
		sender, err = client.NewTlsSender("tcp", config.IpAddress, goTlsConfig)
	} else {
		sender, err = client.NewNetworkSender("tcp", config.IpAddress)
	}
	if err != nil {
		client.LogError.Fatalf("Error creating sender: %s\n", err.Error())
	}
	encoder := client.NewProtobufEncoder(&config.Signer)
	manager := client.NewClient(sender, encoder)

	hostname, _ := os.Hostname()
	msg := &message.Message{}
	msg.SetLogger(pipeline.HEKA_DAEMON) // identify the message as 'internal' for filtering purposes
	msg.SetType("heka.control.sandbox")
	msg.SetTimestamp(time.Now().UnixNano())
	msg.SetUuid(uuid.NewRandom())
	msg.SetHostname(hostname)

	switch *action {
	case "load":
		code, err := ioutil.ReadFile(*scriptFile)
		if err != nil {
			client.LogError.Printf("Error reading scriptFile: %s\n", err.Error())
			return
		}
		msg.SetPayload(string(code))
		conf, err := ioutil.ReadFile(*scriptConfig)
		if err != nil {
			client.LogError.Printf("Error reading scriptConfig: %s\n", err.Error())
			return
		}
		f, _ := message.NewField("config", string(conf), "toml")
		msg.AddField(f)
	case "unload":
		f, _ := message.NewField("name", *filterName, "")
		msg.AddField(f)
	default:
		client.LogError.Printf("Invalid action: %s", *action)
	}

	f1, _ := message.NewField("action", *action, "")
	msg.AddField(f1)
	err = manager.SendMessage(msg)
	if err != nil {
		client.LogError.Printf("Error sending message: %s\n", err.Error())
	}
}
开发者ID:Nitro,项目名称:heka,代码行数:68,代码来源:main.go


示例17: main

func main() {
	configFile := flag.String("config", "sbmgrload.toml", "Sandbox manager load configuration file")
	action := flag.String("action", "load", "load/unload")
	numItems := flag.Int("num", 1, "Number of sandboxes to load/unload")
	flag.Parse()

	code := `
lastTime = os.time() * 1e9
lastCount = 0
count = 0
rate = 0.0
rates = {}

function process_message ()
    count = count + 1
    return 0
end

function timer_event(ns)
    local msgsSent = count - lastCount
    if msgsSent == 0 then return end

    local elapsedTime = ns - lastTime
    if elapsedTime == 0 then return end

    lastCount = count
    lastTime = ns
    rate = msgsSent / (elapsedTime / 1e9)
    rates[#rates+1] = rate
    output(string.format("Got %d messages. %0.2f msg/sec", count, rate))
    inject_message()

    local samples = #rates
    if samples == 10 then -- generate a summary every 10 samples
        table.sort(rates)
	     local min = rates[1]
	     local max = rates[samples]
	     local sum = 0
        for i, val in ipairs(rates) do
            sum = sum + val
	     end
        output(string.format("AGG Sum. Min: %0.2f Max: %0.2f Mean: %0.2f", min, max, sum/samples))
        inject_message()
	     rates = {}
    end
end
`
	confFmt := `
[CounterSandbox%d]
type = "SandboxFilter"
message_matcher = "Type == 'hekabench'"
ticker_interval = 1.0
	[CounterSandbox%d.settings]
    type = "lua"
    filename = ""
    preserve_data = true
    memory_limit = 32767
    instruction_limit = 1000
    output_limit = 1024
`

	var config SbmgrConfig
	if _, err := toml.DecodeFile(*configFile, &config); err != nil {
		log.Printf("Error decoding config file: %s", err)
		return
	}
	sender, err := client.NewNetworkSender("tcp", config.IpAddress)
	if err != nil {
		log.Fatalf("Error creating sender: %s\n", err.Error())
	}
	encoder := client.NewProtobufEncoder(&config.Signer)
	manager := client.NewClient(sender, encoder)
	hostname, _ := os.Hostname()

	switch *action {
	case "load":
		for i := 0; i < *numItems; i++ {
			conf := fmt.Sprintf(confFmt, i, i)
			msg := &message.Message{}
			msg.SetType("heka.control.sandbox")
			msg.SetTimestamp(time.Now().UnixNano())
			msg.SetUuid(uuid.NewRandom())
			msg.SetHostname(hostname)
			msg.SetPayload(code)
			f, _ := message.NewField("config", conf, message.Field_RAW)
			msg.AddField(f)
			f1, _ := message.NewField("action", *action, message.Field_RAW)
			msg.AddField(f1)
			err = manager.SendMessage(msg)
			if err != nil {
				log.Printf("Error sending message: %s\n", err.Error())
			}
		}
	case "unload":
		for i := 0; i < *numItems; i++ {
			msg := &message.Message{}
			msg.SetType("heka.control.sandbox")
			msg.SetTimestamp(time.Now().UnixNano())
			msg.SetUuid(uuid.NewRandom())
			msg.SetHostname(hostname)
//.........这里部分代码省略.........
开发者ID:hellcoderz,项目名称:heka,代码行数:101,代码来源:main.go


示例18: main

func main() {
	configFile := flag.String("config", "flood.toml", "Flood configuration file")
	configTest := flag.String("test", "default", "Test section to load")

	flag.Parse()

	if flag.NFlag() == 0 {
		flag.PrintDefaults()
		os.Exit(0)
	}

	var config FloodConfig
	if _, err := toml.DecodeFile(*configFile, &config); err != nil {
		log.Printf("Error decoding config file: %s", err)
		return
	}
	var test FloodTest
	var ok bool
	if test, ok = config[*configTest]; !ok {
		log.Printf("Configuration test: '%s' was not found", *configTest)
		return
	}

	if test.PprofFile != "" {
		profFile, err := os.Create(test.PprofFile)
		if err != nil {
			log.Fatalln(err)
		}
		pprof.StartCPUProfile(profFile)
		defer pprof.StopCPUProfile()
	}

	sender, err := client.NewNetworkSender(test.Sender, test.IpAddress)
	if err != nil {
		log.Fatalf("Error creating sender: %s\n", err.Error())
	}

	var unsignedEncoder client.Encoder
	var signedEncoder client.Encoder
	switch test.Encoder {
	case "json":
		unsignedEncoder = client.NewJsonEncoder(nil)
		signedEncoder = client.NewJsonEncoder(&test.Signer)
	case "protobuf":
		unsignedEncoder = client.NewProtobufEncoder(nil)
		signedEncoder = client.NewProtobufEncoder(&test.Signer)
	}

	var numTestMessages = 1
	var unsignedMessages [][]byte
	var signedMessages [][]byte

	rdm := &randomDataMaker{
		src:       rand.NewSource(time.Now().UnixNano()),
		asciiOnly: test.AsciiOnly,
	}

	if test.VariableSizeMessages {
		numTestMessages = 64
		unsignedMessages = makeVariableMessage(unsignedEncoder, numTestMessages, rdm)
		signedMessages = makeVariableMessage(signedEncoder, numTestMessages, rdm)
	} else {
		if test.StaticMessageSize == 0 {
			test.StaticMessageSize = 1000
		}
		unsignedMessages = makeFixedMessage(unsignedEncoder, test.StaticMessageSize,
			rdm)
		signedMessages = makeFixedMessage(signedEncoder, test.StaticMessageSize,
			rdm)
	}
	// wait for sigint
	sigChan := make(chan os.Signal, 1)
	signal.Notify(sigChan, syscall.SIGINT)
	var msgsSent, bytesSent uint64
	var corruptPercentage, lastCorruptPercentage, signedPercentage, lastSignedPercentage float64
	var corrupt bool

	// set up counter loop
	ticker := time.NewTicker(time.Duration(time.Second))
	go timerLoop(&msgsSent, &bytesSent, ticker)

	test.CorruptPercentage /= 100.0
	test.SignedPercentage /= 100.0

	var buf []byte
	for gotsigint := false; !gotsigint; {
		runtime.Gosched()
		select {
		case <-sigChan:
			gotsigint = true
			continue
		default:
		}
		msgId := rand.Int() % numTestMessages
		corruptPercentage = math.Floor(float64(msgsSent) * test.CorruptPercentage)
		if corruptPercentage != lastCorruptPercentage {
			lastCorruptPercentage = corruptPercentage
			corrupt = true
		} else {
			corrupt = false
//.........这里部分代码省略.........
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:101,代码来源:main.go



注:本文中的github.com/bbangert/toml.DecodeFile函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang toml.PrimitiveDecode函数代码示例发布时间:2022-05-24
下一篇:
Golang toml.Decode函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap