本文整理匯總了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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)
}
}
示例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)
}
示例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)
}
示例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)
}
示例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
}
示例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))
}
}
示例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)
}