當前位置: 首頁>>代碼示例>>Golang>>正文


Golang config.Get函數代碼示例

本文整理匯總了Golang中github.com/tsuru/config.Get函數的典型用法代碼示例。如果您正苦於以下問題:Golang Get函數的具體用法?Golang Get怎麽用?Golang Get使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Get函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: GetConfig

func (i *NamedIaaS) GetConfig(name string) (interface{}, error) {
	val, err := config.Get(fmt.Sprintf("iaas:custom:%s:%s", i.IaaSName, name))
	if err != nil {
		val, err = config.Get(fmt.Sprintf("iaas:%s:%s", i.BaseIaaSName, name))
	}
	return val, err
}
開發者ID:tsuru,項目名稱:tsuru,代碼行數:7,代碼來源:iaas.go

示例2: List

func List() ([]PlanRouter, error) {
	routerConfig, err := config.Get("routers")
	var routers map[interface{}]interface{}
	if err == nil {
		routers, _ = routerConfig.(map[interface{}]interface{})
	}
	routersList := make([]PlanRouter, 0, len(routers))
	var keys []string
	for key := range routers {
		keys = append(keys, key.(string))
	}
	topLevelHipacheConfig, _ := config.Get("hipache")
	if topLevelHipacheConfig != nil {
		keys = append(keys, "hipache")
	}
	sort.Strings(keys)
	for _, value := range keys {
		var routerType string
		routerProperties, _ := routers[value].(map[interface{}]interface{})
		if routerProperties != nil {
			routerType, _ = routerProperties["type"].(string)
		}
		if routerType == "" {
			routerType = value
		}
		routersList = append(routersList, PlanRouter{Name: value, Type: routerType})
	}
	return routersList, nil
}
開發者ID:RichardKnop,項目名稱:tsuru,代碼行數:29,代碼來源:router.go

示例3: getDefaultIaasName

func getDefaultIaasName() (string, error) {
	defaultIaaS, err := config.GetString("iaas:default")
	if err == nil {
		return defaultIaaS, nil
	}
	ec2ProviderName := "ec2"
	ec2Configured := false
	var configuredIaases []string
	for provider := range iaasProviders {
		if _, err = config.Get(fmt.Sprintf("iaas:%s", provider)); err == nil {
			configuredIaases = append(configuredIaases, provider)
			if provider == ec2ProviderName {
				ec2Configured = true
			}
		}
	}
	c, err := config.Get("iaas:custom")
	if err == nil {
		if v, ok := c.(map[interface{}]interface{}); ok {
			for provider := range v {
				configuredIaases = append(configuredIaases, provider.(string))
			}
		}
	}
	if len(configuredIaases) == 1 {
		return configuredIaases[0], nil
	}
	if ec2Configured {
		return ec2ProviderName, nil
	}
	return "", ErrNoDefaultIaaS
}
開發者ID:tsuru,項目名稱:tsuru,代碼行數:32,代碼來源:iaas.go

示例4: CheckRouter

// Check Router
// It's verify your router configuration and validate related confs.
func CheckRouter() error {
	if router, err := config.Get("docker:router"); err == nil && router == "hipache" {
		if hipache, err := config.Get("hipache"); err != nil || hipache == nil {
			return fmt.Errorf("You should configure hipache router")
		}
	}
	return nil
}
開發者ID:rualatngua,項目名稱:tsuru,代碼行數:10,代碼來源:checker.go

示例5: TestGetAWSAuth

func (s *S) TestGetAWSAuth(c *gocheck.C) {
	access, err := config.Get("aws:access-key-id")
	c.Assert(err, gocheck.IsNil)
	secret, err := config.Get("aws:secret-access-key")
	c.Assert(err, gocheck.IsNil)
	auth := getAWSAuth()
	c.Assert(auth.AccessKey, gocheck.Equals, access)
	c.Assert(auth.SecretKey, gocheck.Equals, secret)
}
開發者ID:rpeterson,項目名稱:tsuru,代碼行數:9,代碼來源:aws_test.go

示例6: checkBeanstalkd

func checkBeanstalkd() error {
	if value, _ := config.Get("queue"); value == "beanstalkd" {
		return errors.New("beanstalkd is no longer supported, please use redis instead")
	}
	if _, err := config.Get("queue-server"); err == nil {
		return errors.New(`beanstalkd is no longer supported, please remove the "queue-server" setting from your config file`)
	}
	return nil
}
開發者ID:zhenruyan,項目名稱:tsuru,代碼行數:9,代碼來源:checker.go

示例7: dial

func (factory *redisPubSubFactory) dial() (redis.Conn, error) {
	host, err := config.GetString("pubsub:redis-host")
	if err != nil {
		host, err = config.GetString("redis-queue:host")
		if err != nil {
			host = "localhost"
		}
	}
	port, err := config.Get("pubsub:redis-port")
	if err != nil {
		port, err = config.Get("redis-queue:port")
		if err != nil {
			port = "6379"
		}
	}
	port = fmt.Sprintf("%v", port)
	password, err := config.GetString("pubsub:redis-password")
	if err != nil {
		password, _ = config.GetString("redis-queue:password")
	}
	db, err := config.GetInt("pubsub:redis-db")
	if err != nil {
		db, err = config.GetInt("redis-queue:db")
		if err != nil {
			db = 3
		}
	}
	secondFloat := float64(time.Second)
	dialTimeout, err := config.GetFloat("pubsub:redis-dial-timeout")
	if err != nil {
		dialTimeout = 0.1
	}
	dialTimeout = dialTimeout * secondFloat
	readTimeout, err := config.GetFloat("pubsub:redis-read-timeout")
	if err != nil {
		readTimeout = 30 * 60
	}
	readTimeout = readTimeout * secondFloat
	writeTimeout, err := config.GetFloat("pubsub:redis-write-timeout")
	if err != nil {
		writeTimeout = 0.5
	}
	writeTimeout = writeTimeout * secondFloat
	conn, err := redis.DialTimeout("tcp", fmt.Sprintf("%s:%v", host, port), time.Duration(dialTimeout), time.Duration(readTimeout), time.Duration(writeTimeout))
	if err != nil {
		return nil, err
	}
	if password != "" {
		_, err = conn.Do("AUTH", password)
		if err != nil {
			return nil, err
		}
	}
	_, err = conn.Do("SELECT", db)
	return conn, err
}
開發者ID:nicolas2bonfils,項目名稱:tsuru,代碼行數:56,代碼來源:redismq.go

示例8: GetConfigString

func (i *NamedIaaS) GetConfigString(name string) (string, error) {
	val, err := config.Get(fmt.Sprintf("iaas:custom:%s:%s", i.IaaSName, name))
	if err != nil {
		val, err = config.Get(fmt.Sprintf("iaas:%s:%s", i.BaseIaaSName, name))
	}
	if err != nil || val == nil {
		return "", err
	}
	return fmt.Sprintf("%v", val), nil
}
開發者ID:zhenruyan,項目名稱:tsuru,代碼行數:10,代碼來源:iaas.go

示例9: CheckScheduler

// Check Schedulers
// It's verify your scheduler configuration and validate related confs.
func CheckScheduler() error {
	if scheduler, err := config.Get("docker:segregate"); err == nil && scheduler == true {
		if servers, err := config.Get("docker:servers"); err == nil && servers != nil {
			return fmt.Errorf("Your scheduler is the segregate. Please remove the servers conf in docker.")
		}
		return nil
	}
	if servers, err := config.Get("docker:servers"); err != nil || servers == nil {
		return fmt.Errorf("You should configure the docker servers.")
	}
	return nil
}
開發者ID:rualatngua,項目名稱:tsuru,代碼行數:14,代碼來源:checker.go

示例10: TestConnectDefaultSettings

func (s *S) TestConnectDefaultSettings(c *gocheck.C) {
	oldURL, _ := config.Get("database:url")
	defer config.Set("database:url", oldURL)
	oldName, _ := config.Get("database:name")
	defer config.Set("database:name", oldName)
	config.Unset("database:url")
	config.Unset("database:name")
	conn, err := Conn()
	c.Assert(err, gocheck.IsNil)
	defer conn.Close()
	c.Assert(conn.User().Database.Name, gocheck.Equals, "gandalf")
	c.Assert(conn.User().Database.Session.LiveServers(), gocheck.DeepEquals, []string{"127.0.0.1:27017"})
}
開發者ID:rfloriano,項目名稱:gandalf,代碼行數:13,代碼來源:conn_test.go

示例11: TestDbConfig

func (s *S) TestDbConfig(c *check.C) {
	oldURL, _ := config.Get("database:url")
	defer config.Set("database:url", oldURL)
	oldName, _ := config.Get("database:name")
	defer config.Set("database:name", oldName)
	url, dbname := DbConfig()
	c.Assert(url, check.Equals, oldURL)
	c.Assert(dbname, check.Equals, oldName)
	config.Unset("database:url")
	config.Unset("database:name")
	url, dbname = DbConfig()
	c.Assert(url, check.Equals, "127.0.0.1:27017")
	c.Assert(dbname, check.Equals, "gandalf")
}
開發者ID:tsuru,項目名稱:gandalf,代碼行數:14,代碼來源:conn_test.go

示例12: WebProcessDefaultPort

func WebProcessDefaultPort() string {
	port, err := config.Get("docker:run-cmd:port")
	if err != nil {
		return "8888"
	}
	return fmt.Sprint(port)
}
開發者ID:tsuru,項目名稱:tsuru,代碼行數:7,代碼來源:commands.go

示例13: TestAddBackendWithVpc

func (s *S) TestAddBackendWithVpc(c *gocheck.C) {
	old, _ := config.Get("juju:elb-avail-zones")
	config.Unset("juju:elb-avail-zones")
	config.Set("juju:elb-use-vpc", true)
	config.Set("juju:elb-vpc-subnets", []string{"subnet-a4a3a2a1", "subnet-002200"})
	config.Set("juju:elb-vpc-secgroups", []string{"sg-0900"})
	defer func() {
		config.Set("juju:elb-avail-zones", old)
		config.Unset("juju:elb-use-vpc")
		config.Unset("juju:elb-vpc-subnets")
		config.Unset("juju:elb-vpc-secgroups")
	}()
	router := elbRouter{}
	err := router.AddBackend("tip")
	c.Assert(err, gocheck.IsNil)
	defer router.RemoveBackend("tip")
	resp, err := s.client.DescribeLoadBalancers("tip")
	c.Assert(err, gocheck.IsNil)
	c.Assert(resp.LoadBalancerDescriptions, gocheck.HasLen, 1)
	lbd := resp.LoadBalancerDescriptions[0]
	c.Assert(lbd.Subnets, gocheck.DeepEquals, []string{"subnet-a4a3a2a1", "subnet-002200"})
	c.Assert(lbd.SecurityGroups, gocheck.DeepEquals, []string{"sg-0900"})
	c.Assert(lbd.Scheme, gocheck.Equals, "internal")
	c.Assert(lbd.AvailZones, gocheck.HasLen, 0)
}
開發者ID:rochacon,項目名稱:tsuru,代碼行數:25,代碼來源:router_test.go

示例14: getPort

func getPort() (string, error) {
	port, err := config.Get("docker:run-cmd:port")
	if err != nil {
		return "", err
	}
	return fmt.Sprint(port), nil
}
開發者ID:tomzhang,項目名稱:golang-devops-stuff,代碼行數:7,代碼來源:docker.go

示例15: BuildHealthCheck

// BuildHealthCheck creates a healthcheck function for the given routerName.
//
// It will call the HealthCheck() method in the router (only if it's also a
// HealthChecker), for each instance of it (including the "main" instance and
// all custom routers).
func BuildHealthCheck(routerName string) func() error {
	return func() error {
		routerConfig, err := config.Get("routers")
		if err != nil {
			return hc.ErrDisabledComponent
		}
		routers, _ := routerConfig.(map[interface{}]interface{})
		checkCount := 0
		for ifaceName := range routers {
			name := ifaceName.(string)
			if name != routerName {
				namedRouter := routers[name].(map[interface{}]interface{})
				if tp, _ := namedRouter["type"].(string); tp != routerName {
					continue
				}
			}
			checkCount++
			err := healthCheck(name)
			if err != nil {
				return err
			}
		}
		if checkCount == 0 {
			return hc.ErrDisabledComponent
		}
		return nil
	}
}
開發者ID:tsuru,項目名稱:tsuru,代碼行數:33,代碼來源:hc.go


注:本文中的github.com/tsuru/config.Get函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。