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

Golang config.GetAsInt函数代码示例

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

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



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

示例1: configureCommonParams

// configureCommonParams will extract the common parameters that are used and set them in the handler
func (base *BaseHandler) configureCommonParams(configMap map[string]interface{}) {
	if asInterface, exists := configMap["timeout"]; exists {
		timeout := config.GetAsFloat(asInterface, DefaultTimeoutSec)
		base.timeout = time.Duration(timeout) * time.Second
	}

	if asInterface, exists := configMap["max_buffer_size"]; exists {
		base.maxBufferSize = config.GetAsInt(asInterface, DefaultBufferSize)
	}

	if asInterface, exists := configMap["interval"]; exists {
		base.interval = config.GetAsInt(asInterface, DefaultInterval)
	}

	// Default dimensions can be extended or overridden on a per handler basis.
	if asInterface, exists := configMap["defaultDimensions"]; exists {
		handlerLevelDimensions := config.GetAsMap(asInterface)
		base.SetDefaultDimensions(handlerLevelDimensions)
	}

	if asInterface, exists := configMap["keepAliveInterval"]; exists {
		keepAliveInterval := config.GetAsInt(asInterface, DefaultKeepAliveInterval)
		base.SetKeepAliveInterval(keepAliveInterval)
	}

	if asInterface, exists := configMap["maxIdleConnectionsPerHost"]; exists {
		maxIdleConnectionsPerHost := config.GetAsInt(asInterface,
			DefaultMaxIdleConnectionsPerHost)
		base.SetMaxIdleConnectionsPerHost(maxIdleConnectionsPerHost)
	}
}
开发者ID:gsalisbury,项目名称:fullerite,代码行数:32,代码来源:handler.go


示例2: Configure

// Configure Override *baseCollector.Configure(). Will create the required MesosLeaderElect instance.
func (m *MesosSlaveStats) Configure(configMap map[string]interface{}) {
	m.configureCommonParams(configMap)
	c := config.GetAsMap(configMap)

	if httpTimeout, exists := c["httpTimeout"]; exists {
		m.client.Timeout = time.Duration(config.GetAsInt(httpTimeout, httpDefaultTimeout)) * time.Second
	}

	if slaveSnapshotPort, exists := c["slaveSnapshotPort"]; exists {
		m.snapshotPort = config.GetAsInt(slaveSnapshotPort, mesosDefaultSlaveSnapshotPort)
	}
}
开发者ID:EvanKrall,项目名称:fullerite,代码行数:13,代码来源:mesos_slave.go


示例3: TestGetInt

func TestGetInt(t *testing.T) {
	assert := assert.New(t)

	val := config.GetAsInt("10", 123)
	assert.Equal(val, 10)

	val = config.GetAsInt("notanint", 123)
	assert.Equal(val, 123)

	val = config.GetAsInt(12.123, 123)
	assert.Equal(val, 12)

	val = config.GetAsInt(12, 123)
	assert.Equal(val, 12)
}
开发者ID:jp2007,项目名称:fullerite,代码行数:15,代码来源:config_test.go


示例4: Configure

// Configure takes a dictionary of values with which the handler can configure itself.
func (d *DockerStats) Configure(configMap map[string]interface{}) {
	if timeout, exists := configMap["dockerStatsTimeout"]; exists {
		d.statsTimeout = min(config.GetAsInt(timeout, d.interval), d.interval)
	} else {
		d.statsTimeout = d.interval
	}
	if dockerEndpoint, exists := configMap["dockerEndPoint"]; exists {
		if str, ok := dockerEndpoint.(string); ok {
			d.endpoint = str
		} else {
			d.log.Warn("Failed to cast dokerEndPoint: ", reflect.TypeOf(dockerEndpoint))
		}
	} else {
		d.endpoint = endpoint
	}
	d.dockerClient, _ = docker.NewClient(d.endpoint)
	if generatedDimensions, exists := configMap["generatedDimensions"]; exists {
		for dimension, generator := range generatedDimensions.(map[string]interface{}) {
			for key, regx := range config.GetAsMap(generator) {
				re, err := regexp.Compile(regx)
				if err != nil {
					d.log.Warn("Failed to compile regex: ", regx, err)
				} else {
					d.compiledRegex[dimension] = &Regex{regex: re, tag: key}
				}
			}
		}
	}
	d.configureCommonParams(configMap)
	if skipRegex, skipExists := configMap["skipContainerRegex"]; skipExists {
		d.skipRegex = regexp.MustCompile(skipRegex.(string))
	}
}
开发者ID:EvanKrall,项目名称:fullerite,代码行数:34,代码来源:docker_stats.go


示例5: ParseNerveConfig

// ParseNerveConfig is responsible for taking the JSON string coming in into a map of service:port
// it will also filter based on only services runnign on this host.
// To deal with multi-tenancy we actually will return port:service
func ParseNerveConfig(raw *[]byte) (map[int]string, error) {
	results := make(map[int]string)
	ips, err := ipGetter()

	if err != nil {
		return results, err
	}
	parsed := new(nerveConfigData)

	// convert the ips into a map for membership tests
	ipMap := make(map[string]bool)
	for _, val := range ips {
		ipMap[val] = true
	}

	err = json.Unmarshal(*raw, parsed)
	if err != nil {
		return results, err
	}

	for rawServiceName, serviceConfig := range parsed.Services {
		host := strings.TrimSpace(serviceConfig["host"].(string))

		_, exists := ipMap[host]
		if exists {
			name := strings.Split(rawServiceName, ".")[0]
			port := config.GetAsInt(serviceConfig["port"], -1)
			if port != -1 {
				results[port] = name
			}
		}
	}

	return results, nil
}
开发者ID:venkey-ariv,项目名称:fullerite,代码行数:38,代码来源:nerve_config.go


示例6: parseNerveConfig

// parseNerveConfig is responsible for taking the JSON string coming in into a map of service:port
// it will also filter based on only services runnign on this host.
// To deal with multi-tenancy we actually will return port:service
func (n *nerveUWSGICollector) parseNerveConfig(raw *[]byte, ips []string) (map[int]string, error) {
	parsed := new(releventNerveConfig)

	// convert the ips into a map for membership tests
	ipMap := make(map[string]bool)
	for _, val := range ips {
		ipMap[val] = true
	}

	err := json.Unmarshal(*raw, parsed)
	if err != nil {
		return make(map[int]string), err
	}
	results := make(map[int]string)
	for rawServiceName, serviceConfig := range parsed.Services {
		host := strings.TrimSpace(serviceConfig["host"].(string))

		_, exists := ipMap[host]
		if exists {
			name := strings.Split(rawServiceName, ".")[0]
			port := config.GetAsInt(serviceConfig["port"], -1)
			if port != -1 {
				results[port] = name
			} else {
				n.log.Warn("Failed to get port from value ", serviceConfig["port"])
			}
		}
	}

	return results, nil
}
开发者ID:yeled,项目名称:fullerite,代码行数:34,代码来源:nerve_uwsgi.go


示例7: Configure

// Configure accepts the different configuration options for the signalfx handler
func (s *SignalFx) Configure(configMap map[string]interface{}) {
	if authToken, exists := configMap["authToken"]; exists == true {
		s.authToken = authToken.(string)
	} else {
		s.log.Error("There was no auth key specified for the SignalFx Handler, there won't be any emissions")
	}
	if endpoint, exists := configMap["endpoint"]; exists == true {
		s.endpoint = endpoint.(string)
	} else {
		s.log.Error("There was no endpoint specified for the SignalFx Handler, there won't be any emissions")
	}
	if timeout, exists := configMap["timeout"]; exists == true {
		val, err := config.GetAsFloat(timeout)
		if err != nil {
			s.log.Error("Failed to parse the value", timeout, "into a float")
		} else {
			s.timeout = time.Duration(val) * time.Second
		}
	}
	if bufferSize, exists := configMap["max_buffer_size"]; exists == true {
		val, err := config.GetAsInt(bufferSize)
		if err != nil {
			s.log.Error("Failed to parse the value", bufferSize, "into an int")
		} else {
			s.maxBufferSize = val
		}
	}
}
开发者ID:jaxxstorm,项目名称:fullerite,代码行数:29,代码来源:signalfx.go


示例8: Configure

// Configure takes a dictionary of values with which the handler can configure itself.
func (d *DockerStats) Configure(configMap map[string]interface{}) {
	d.configureCommonParams(configMap)
	if timeout, exists := configMap["dockerStatsTimeout"]; exists {
		d.statsTimeout = min(config.GetAsInt(timeout, d.interval), d.interval)
	} else {
		d.statsTimeout = d.interval
	}
}
开发者ID:yeled,项目名称:fullerite,代码行数:9,代码来源:docker_stats.go


示例9: configure

func (srv *InternalServer) configure(cfgMap map[string]interface{}) {

	if val, exists := (cfgMap)["port"]; exists {
		srv.port = config.GetAsInt(val, defaultPort)
	} else {
		srv.port = defaultPort
	}

	if val, exists := (cfgMap)["path"]; exists {
		srv.path = val.(string)
	} else {
		srv.path = defaultMetricsPath
	}
}
开发者ID:EvanKrall,项目名称:fullerite,代码行数:14,代码来源:internal_metrics_server.go


示例10: getCollectorBatchSize

func getCollectorBatchSize(collectorName string,
	globalConfig config.Config,
	defaultBufSize int) (result int) {
	conf, err := globalConfig.GetCollectorConfig(collectorName)
	result = defaultBufSize
	if err != nil {
		return
	}

	if bufferSize, exists := conf["max_buffer_size"]; exists {
		result = config.GetAsInt(bufferSize, defaultBufSize)
	}
	return
}
开发者ID:Yelp,项目名称:fullerite,代码行数:14,代码来源:handler.go


示例11: Configure

// Configure accepts the different configuration options for the Scribe handler
func (s *Scribe) Configure(configMap map[string]interface{}) {
	if endpoint, exists := configMap["endpoint"]; exists {
		s.endpoint = endpoint.(string)
	}

	if port, exists := configMap["port"]; exists {
		s.port = config.GetAsInt(port, defaultScribePort)
	}

	if stream, exists := configMap["streamName"]; exists {
		s.streamName = stream.(string)
	}

	s.configureCommonParams(configMap)
}
开发者ID:sagar8192,项目名称:fullerite,代码行数:16,代码来源:scribe.go


示例12: startCollector

func startCollector(name string, globalConfig config.Config, instanceConfig map[string]interface{}) collector.Collector {
	log.Debug("Starting collector ", name)
	collectorInst := collector.New(name)
	if collectorInst == nil {
		return nil
	}

	// apply the global configs
	collectorInst.SetInterval(config.GetAsInt(globalConfig.Interval, collector.DefaultCollectionInterval))

	// apply the instance configs
	collectorInst.Configure(instanceConfig)

	go runCollector(collectorInst)
	return collectorInst
}
开发者ID:gsalisbury,项目名称:fullerite,代码行数:16,代码来源:collectors.go


示例13: configureCommonParams

func (col *baseCollector) configureCommonParams(configMap map[string]interface{}) {
	if interval, exists := configMap["interval"]; exists {
		col.interval = config.GetAsInt(interval, DefaultCollectionInterval)
	}

	if prefix, exists := configMap["prefix"]; exists {
		if str, ok := prefix.(string); ok {
			col.prefix = str
		}
	}

	if asInterface, exists := configMap["metrics_blacklist"]; exists {
		col.blacklist = config.GetAsSlice(asInterface)
	}

}
开发者ID:Yelp,项目名称:fullerite,代码行数:16,代码来源:collector.go


示例14: Configure

// Rewrites config variables from the global config
func (n *uWSGINerveWorkerStatsCollector) Configure(configMap map[string]interface{}) {
	if val, exists := configMap["queryPath"]; exists {
		n.queryPath = val.(string)
	}
	if val, exists := configMap["configFilePath"]; exists {
		n.configFilePath = val.(string)
	}
	if val, exists := configMap["servicesWhitelist"]; exists {
		n.servicesWhitelist = config.GetAsSlice(val)
	}

	if val, exists := configMap["http_timeout"]; exists {
		n.timeout = config.GetAsInt(val, 2)
	}

	n.configureCommonParams(configMap)
}
开发者ID:Yelp,项目名称:fullerite,代码行数:18,代码来源:uwsgi_nerve_worker_stats.go


示例15: startHandler

func startHandler(name string, globalConfig config.Config, instanceConfig map[string]interface{}) handler.Handler {
	log.Info("Starting handler ", name)
	handlerInst := handler.New(name)
	if handlerInst == nil {
		return nil
	}

	// apply any global configs
	handlerInst.SetInterval(config.GetAsInt(globalConfig.Interval, handler.DefaultInterval))
	handlerInst.SetPrefix(globalConfig.Prefix)
	handlerInst.SetDefaultDimensions(globalConfig.DefaultDimensions)

	// now apply the handler level configs
	handlerInst.Configure(instanceConfig)

	go handlerInst.Run()
	return handlerInst
}
开发者ID:carriercomm,项目名称:fullerite,代码行数:18,代码来源:handlers.go


示例16: createHandler

func createHandler(name string, globalConfig config.Config, instanceConfig map[string]interface{}) handler.Handler {
	handlerInst := handler.New(name)
	if handlerInst == nil {
		return nil
	}

	// apply any global configs
	handlerInst.SetInterval(config.GetAsInt(globalConfig.Interval, handler.DefaultInterval))
	handlerInst.SetPrefix(globalConfig.Prefix)
	handlerInst.SetDefaultDimensions(globalConfig.DefaultDimensions)

	// now apply the handler level configs
	handlerInst.Configure(instanceConfig)

	// now run a listener channel for each collector
	handlerInst.InitListeners(globalConfig)

	return handlerInst
}
开发者ID:Yelp,项目名称:fullerite,代码行数:19,代码来源:handlers.go


示例17: Configure

// Configure the collector
func (c *NerveHTTPD) Configure(configMap map[string]interface{}) {
	if val, exists := configMap["queryPath"]; exists {
		c.queryPath = val.(string)
	}
	if val, exists := configMap["configFilePath"]; exists {
		c.configFilePath = val.(string)
	}

	if val, exists := configMap["host"]; exists {
		c.host = val.(string)
	}

	if val, exists := configMap["status_ttl"]; exists {
		tmpStatusTTL := config.GetAsInt(val, 3600)
		c.statusTTL = time.Duration(tmpStatusTTL) * time.Second
	}

	c.configureCommonParams(configMap)
}
开发者ID:venkey-ariv,项目名称:fullerite,代码行数:20,代码来源:nerve_httpd.go


示例18: Configure

// Configure takes a dictionary of values with which the handler can configure itself.
func (d *DockerStats) Configure(configMap map[string]interface{}) {
	if timeout, exists := configMap["dockerStatsTimeout"]; exists {
		d.statsTimeout = min(config.GetAsInt(timeout, d.interval), d.interval)
	} else {
		d.statsTimeout = d.interval
	}
	if generatedDimensions, exists := configMap["generatedDimensions"]; exists {
		for dimension, generator := range generatedDimensions.(map[string]interface{}) {
			for key, regx := range config.GetAsMap(generator) {
				re, err := regexp.Compile(regx)
				if err != nil {
					d.log.Warn("Failed to compile regex: ", regx, err)
				} else {
					d.compiledRegex[dimension] = &Regex{regex: re, tag: key}
				}
			}
		}
	}
	d.configureCommonParams(configMap)
}
开发者ID:sagar8192,项目名称:fullerite,代码行数:21,代码来源:docker_stats.go


示例19: configureCommonParams

func (col *baseCollector) configureCommonParams(configMap map[string]interface{}) {
	if interval, exists := configMap["interval"]; exists {
		col.interval = config.GetAsInt(interval, DefaultCollectionInterval)
	}
}
开发者ID:yeled,项目名称:fullerite,代码行数:5,代码来源:collector.go


示例20: Configure

// Configure takes a dictionary of values with which the handler can configure itself.
func (d *DockerStats) Configure(configMap map[string]interface{}) {
	if timeout, exists := configMap["dockerStatsTimeout"]; exists {
		d.statsTimeout = config.GetAsInt(timeout, defaultStatsTimeout)
	}
	d.configureCommonParams(configMap)
}
开发者ID:dichiarafrancesco,项目名称:fullerite,代码行数:7,代码来源:docker_stats.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang config.ReadConfig函数代码示例发布时间:2022-05-24
下一篇:
Golang collector.Collector类代码示例发布时间: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