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

Golang config.AtPath函数代码示例

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

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



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

示例1: getHosts

func getHosts() []string {
	port := config.AtPath("hailo", "service", "cassandra", "defaults", "cqlPort").AsInt(defaultPort)
	hosts := config.AtPath("hailo", "service", "cassandra", hostsCfgKey()).AsHostnameArray(port)
	if len(hosts) > 0 {
		return hosts
	}

	// No hosts returned: try DNS
	tier := config.AtPath("hailo", "service", "cassandra", "tier").AsString("premium")
	hosts, err := dns.Hosts("cassandra-" + tier)
	if err != nil {
		log.Errorf("[Cassandra] Failed to load hosts from DNS: %s", err.Error())
		return defaultHosts
	}

	if len(hosts) == 0 {
		return defaultHosts
	}
	// We need to append the port to hosts coming from DNS
	for i, host := range hosts {
		hosts[i] = host + fmt.Sprintf(":%d", port)
	}

	return hosts
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:25,代码来源:config.go


示例2: getHosts

func getHosts(port int, path ...string) []string {
	if hosts := config.AtPath(path...).AsHostnameArray(port); len(hosts) > 0 {
		return hosts
	}

	// should we lookup dns?
	if config.AtPath("hailo", "service", "nsq", "disableDnsLookup").AsBool() {
		return []string{}
	}

	// try dns lookup
	cluster := config.AtPath("hailo", "service", "nsq", "cluster").AsString("general")
	hosts, err := dns.Hosts("nsq-" + cluster)
	if err != nil {
		log.Errorf("Failed to load NSQ hosts from dns: %v", err)
		return []string{}
	}

	// append port
	for i, host := range hosts {
		hosts[i] = fmt.Sprintf("%s:%d", host, port)
	}

	return hosts
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:25,代码来源:hosts.go


示例3: getHosts

func getHosts() []string {
	cassandraHostKey := getCassandraHostConfigKey()
	config.WaitUntilLoaded(5 * time.Second)
	port := config.AtPath("hailo", "service", "cassandra", "defaults", "thriftPort").AsInt(defaultPort)
	if hosts := config.AtPath("hailo", "service", "cassandra", cassandraHostKey).AsHostnameArray(port); len(hosts) > 0 {
		return hosts
	}

	// No hosts returned: try DNS
	tier := config.AtPath("hailo", "service", "cassandra", "tier").AsString("premium")
	hosts, err := dns.Hosts("cassandra-" + tier)
	if err != nil {
		log.Errorf("Failed to load Cassandra hosts from dns: %v", err)
		return defaultHosts
	}

	if len(hosts) == 0 {
		return defaultHosts
	}
	// We need to append the port to hosts coming from DNS
	for i, host := range hosts {
		hosts[i] = host + fmt.Sprintf(":%d", port)
	}

	return hosts
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:26,代码来源:cassandra.go


示例4: getHosts

func getHosts() []string {
	hostsConfigPath := []string{"hailo", "service", "zookeeper", "hosts"}
	tier := config.AtPath("hailo", "service", "zookeeper", "tier").AsString("general")
	if tier != "general" {
		hostsConfigPath = append(hostsConfigPath, tier)
	}

	if hosts := config.AtPath(hostsConfigPath...).AsHostnameArray(2181); len(hosts) > 0 {
		return hosts
	}

	// no hosts returned so try dns
	hosts, err := dns.Hosts("zookeeper-" + tier)
	if err != nil {
		log.Errorf("Failed to load ZK hosts from dns: %v", err)
		return []string{"localhost:2181"}
	}

	// for safety fall back to localhost
	if len(hosts) == 0 {
		return []string{"localhost:2181"}
	}

	// append port
	for i, host := range hosts {
		hosts[i] = host + ":2181"
	}

	return hosts
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:30,代码来源:zookeeper.go


示例5: getHosts

func getHosts() []string {
	hostConfigPath := []string{"hailo", "service", "memcache", "servers"}
	host := "memcached"

	// check if tier is specified and act accordingly
	tier := config.AtPath("hailo", "service", "memcache", "tier").AsString("")
	if tier != "" {
		hostConfigPath = append(hostConfigPath, tier)
		host = fmt.Sprintf("%s-%s", host, tier)
	}

	if hosts := config.AtPath(hostConfigPath...).AsHostnameArray(11211); len(hosts) > 0 {
		return hosts
	}

	// no hosts returned so try dns
	hosts, err := dns.Hosts(host)
	if err != nil {
		log.Errorf("[Memcache] Failed to load hosts from dns, returning empty list: %v", err)
		return []string{}
	}

	// append port
	for i, host := range hosts {
		hosts[i] = host + ":11211"
	}

	return hosts
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:29,代码来源:memcache.go


示例6: newdefaultClient

func newdefaultClient() MemcacheClient {
	serverSelector := new(memcache.ServerList)
	client := memcache.NewFromSelector(serverSelector)

	// Listen for config changes
	ch := config.SubscribeChanges()
	go func() {
		for _ = range ch {
			loadFromConfig(serverSelector, client)
		}
	}()

	loadFromConfig(serverSelector, client)

	// Log on init
	hosts := config.AtPath("hailo", "service", "memcache", "servers").AsHostnameArray(11211)
	operationTimeout := config.AtPath("hailo", "service", "memcache", "timeouts", "dialTimeout").
		AsDuration(defaultDialTimeout)
	dialTimeout := config.AtPath("hailo", "service", "memcache", "timeouts", "operationTimeout").
		AsDuration(defaultOperationTimeout)

	log.Infof("[Memcache] Initialising Memcache client to hosts %v: dial timeout %v, op timeout: %v", hosts,
		dialTimeout, operationTimeout)

	return client
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:26,代码来源:memcache.go


示例7: createCircuit

func createCircuit(service, endpoint string) Circuit {
	options := defaultOptions
	config.AtPath("hailo", "platform", "circuitbreaker").AsStruct(&options)
	config.AtPath("hailo", "platform", "circuitbreaker", "endpoints", service, endpoint).AsStruct(&options)

	log.Debugf("Circuitbreaker config for %s.%s: %#v", service, endpoint, options)
	return NewDefaultCircuit(options)
}
开发者ID:choirudin2210,项目名称:platform-layer,代码行数:8,代码来源:circuitbreaker.go


示例8: connect

func (rs *RedisDedupeClient) connect() (*redis.Pool, error) {
	host := config.AtPath("hailo", "service", "deduper", "redis", "hostname").AsString(":16379")
	// var password string
	log.Debugf("Setting redis server from config: %v", host)
	pool := &redis.Pool{
		MaxIdle:     3,
		IdleTimeout: 240 * time.Second,
		Dial: func() (redis.Conn, error) {
			c, err := redis.Dial("tcp", host)
			if err != nil {
				return nil, err
			}
			if _, err := c.Do("PING"); err != nil {
				c.Close()
				return nil, err
			}
			return c, err
		},
		TestOnBorrow: func(c redis.Conn, t time.Time) error {
			_, err := c.Do("PING")
			return err
		},
	}

	return pool, nil
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:26,代码来源:dedupe.go


示例9: AddHandlers

func (s *DefaultSubscriber) AddHandlers(handler nsqlib.Handler) {
	subHandlers := config.AtPath("hailo", "service", "nsq", "subHandlers").AsInt(6)
	log.Infof("Adding %d handlers", subHandlers)
	for i := 0; i < subHandlers; i++ {
		s.AddHandler(handler)
	}
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:7,代码来源:subscriber.go


示例10: loadFromConfig

func loadFromConfig(sl *memcache.ServerList, client *memcache.Client) {
	hosts := getHosts()
	log.Tracef("[Memcache] Setting memcache servers from config: %v", hosts)
	err := sl.SetServers(hosts...)
	if err != nil {
		log.Errorf("[Memcache] Error setting memcache servers: %v", err)
	}

	// Technically we have a race here since the timeouts are not protected by a mutex, however it isn't really a
	// problem if the timeout is stale for a short period.
	client.Timeout = config.AtPath("hailo", "service", "memcache", "timeouts", "operationTimeout").
		AsDuration(defaultOperationTimeout)
	log.Tracef("[Memcache] Set Memcache operation timeout from config: %v", client.Timeout)
	client.DialTimeout = config.AtPath("hailo", "service", "memcache", "timeouts", "dialTimeout").
		AsDuration(defaultDialTimeout)
	log.Tracef("[Memcache] Set Memcache dial timeout from config: %v", client.DialTimeout)
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:17,代码来源:memcache.go


示例11: loadFromConfig

// loadFromConfig will grab the configurable settings from config service
func (t *Timeout) loadFromConfig() {
	min := config.AtPath("hailo", "platform", "timeout", "min").AsDuration(defaultMin)
	max := config.AtPath("hailo", "platform", "timeout", "max").AsDuration(defaultMax)
	multiplier := config.AtPath("hailo", "platform", "timeout", "multiplier").AsFloat64(defaultMultiplier)

	// any difference?
	if hashTimeouts(min, max, multiplier) == t.hashTimeouts() {
		return
	}

	t.Lock()
	defer t.Unlock()
	t.min = min
	t.max = max
	t.multiplier = multiplier

	log.Infof("[Client] Loaded timeout configuration from config service [min=%v, max=%v, multiplier=%v]", min, max, multiplier)
}
开发者ID:choirudin2210,项目名称:platform-layer,代码行数:19,代码来源:timeout.go


示例12: NewGlobalLeader

// NewGlobalLocker returns a global leader which is basically just a region leader pinned to one region based on
// config.
func NewGlobalLeader(id string) Leader {
	for {
		if config.AtPath("leaders", "isLeader").AsBool() {
			break
		}
		<-config.SubscribeChanges()
	}
	return RegionLeader(id)
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:11,代码来源:globalleader.go


示例13: loadAccConfig

func loadAccConfig(path ...string) []*AWSAccount {
	bytes := config.AtPath(path...).AsJson()
	accs := make([]*AWSAccount, 0)
	err := json.Unmarshal(bytes, &accs)
	if err != nil {
		log.Warnf("[AWS Manager] Failed to unmarshal AWS credential pairs from config: %s", err)
		return nil
	}
	return accs
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:10,代码来源:mgr.go


示例14: TestPub

func TestPub(t *testing.T) {
	config.LoadFromService("testservice")
	s := config.AtPath("configService", "hash").AsString("default")
	if s == "default" {
		t.Fatal("Failed to load config from config service")
	}
	err := Publish("testtopic", []byte("This is my payload"))
	if err != nil {
		t.Error(fmt.Sprintf("Failed to PUB: %v", err))
	}
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:11,代码来源:integration_test.go


示例15: loadEndpointConfig

func loadEndpointConfig() {
	log.Info("Loading ElasticSearch config")

	port := config.AtPath("hailo", "service", "elasticsearch", "port").AsInt(9200)
	hosts := config.AtPath("hailo", "service", "elasticsearch", "hosts").AsHostnameArray(port)

	if len(hosts) == 0 {
		hosts = append(hosts, "localhost:19200")
	}

	// Set these hosts in the Elasticsearch library
	// This will initialise a host pool which uses an Epsilon Greedy algorithm to find healthy hosts
	// and send to requests to them, and not unhealthy or slow hosts
	eapi.Port = strconv.Itoa(port)
	if port == 443 {
		eapi.Protocol = "https"
	}
	eapi.SetHosts(hosts)

	log.Infof("ElasticSearch hosts loaded: %v", eapi.Hosts)
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:21,代码来源:elasticsearch.go


示例16: ksAuth

// ksAuth returns the username and password for the given keyspace
func ksAuth(ks string) (string, string, error) {
	if !config.AtPath("hailo", "service", "cassandra", "authentication", "enabled").AsBool() {
		return "", "", nil
	}

	confJson := config.AtPath("hailo", "service", "cassandra", "authentication", "keyspaces").AsJson()
	rawConf := make(map[string]map[string]string, 5)
	if err := json.Unmarshal(confJson, &rawConf); err != nil {
		// Don't log raw data in an attempt to not log our passwords
		log.Warnf("[Cassandra] Failed to unmarshal authentication configuration: %s", err.Error())
		return "", "", err
	}

	for candidateKs, v := range rawConf {
		if candidateKs == ks {
			return v["username"], v["password"], nil
		}
	}

	return "", "", nil
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:22,代码来源:config.go


示例17: getKsConfig

func getKsConfig(ks string) (ksConfig, error) {
	if !config.WaitUntilLoaded(5 * time.Second) {
		return ksConfig{}, fmt.Errorf("Config not loaded")
	}

	username, password, err := ksAuth(ks)
	if err != nil {
		return ksConfig{}, err
	}

	c := ksConfig{
		ks:       ks,
		hosts:    getHosts(),
		username: username,
		password: password,
		retries:  config.AtPath("hailo", "service", "cassandra", "defaults", "maxRetries").AsInt(5),
		cl:       clFromString(config.AtPath("hailo", "service", "cassandra", "defaults", "consistencyLevel").AsString("")),
		timeout:  config.AtPath("hailo", "service", "cassandra", "defaults", "recvTimeout").AsDuration("1s"),
	}
	cc := gocql.NewCluster(c.hosts...)
	cc.ProtoVersion = config.AtPath("hailo", "service", "cassandra", "defaults", "protoVersion").AsInt(2)
	cc.Consistency = c.cl
	cc.Compressor = gocql.SnappyCompressor{}
	cc.DiscoverHosts = false
	cc.NumConns = config.AtPath("hailo", "service", "cassandra", "defaults", "maxHostConns").AsInt(2)
	cc.Authenticator = gocql.PasswordAuthenticator{
		Username: c.username,
		Password: c.password,
	}
	cc.Timeout = c.timeout
	cc.Keyspace = c.ks
	cc.RetryPolicy = &gocql.SimpleRetryPolicy{
		NumRetries: c.retries,
	}
	cc.PoolConfig.HostSelectionPolicy = gocql.HostPoolHostPolicy(
		hostpool.NewEpsilonGreedy(c.hosts, 5*time.Minute, &hostpool.LinearEpsilonValueCalculator{}),
	)
	c.cc = cc
	return c, nil
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:40,代码来源:config.go


示例18: loadStatsd

func loadStatsd(addr string) g2s.Statter {
	disabled := config.AtPath("hailo", "service", "instrumentation", "statsd", "disabled").AsBool()
	if disabled {
		return g2s.Noop()
	}

	s, err := g2s.Dial("udp", addr)
	if err != nil {
		log.Warnf("Error initialising statsd connection to %v", addr)
		return nil
	}

	return s
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:14,代码来源:instrumentation.go


示例19: hostsCfgKey

// hostsCfgKey gets the config key that should be used to load cassandra hosts. This is to support multiple 'tiered'
// Cassandra clusters.
func hostsCfgKey() string {
	// Check what cluster are we supposed to contact, revert to the default config if not specified
	tier := config.AtPath("hailo", "service", "cassandra", "tier").AsString("")
	if tier == "" {
		tier = defaultTier
	}

	switch tier {
	case "general":
		return "hosts"
	default:
		return fmt.Sprintf("%sHosts", tier)
	}
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:16,代码来源:config.go


示例20: run

// run is our main healthcheck loop
func (r *results) run() {
	for {
		select {
		// Listen for config changes and update the healthcheck when needed
		case <-config.SubscribeChanges():
			// Allow healthcheck parameters to be overridden in config
			config.AtPath("hailo", "platform", "healthcheck", r.hc.Id).AsStruct(r.hc)
		case <-runNow:
			r.collect()
		case <-time.After(r.hc.Interval):
			r.collect()
		}
	}
}
开发者ID:choirudin2210,项目名称:platform-layer,代码行数:15,代码来源:types.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang ebiten.Run函数代码示例发布时间:2022-05-23
下一篇:
Golang proto.String函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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