当前位置: 首页>>代码示例>>Golang>>正文


Golang config.AtPath函数代码示例

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


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


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