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

Golang config.Get函数代码示例

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

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



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


示例16: TestCheckBeanstalkdDefinedInQueue

func (s *CheckerSuite) TestCheckBeanstalkdDefinedInQueue(c *check.C) {
	old, _ := config.Get("queue")
	defer config.Set("queue", old)
	config.Set("queue", "beanstalkd")
	err := checkBeanstalkd()
	c.Assert(err.Error(), check.Equals, "beanstalkd is no longer supported, please use redis instead")
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:7,代码来源:checker_test.go


示例17: TestContainerCreateUndefinedUser

func (s *S) TestContainerCreateUndefinedUser(c *check.C) {
	oldUser, _ := config.Get("docker:user")
	defer config.Set("docker:user", oldUser)
	config.Unset("docker:user")
	img := "tsuru/python:latest"
	s.p.Cluster().PullImage(docker.PullImageOptions{Repository: img}, docker.AuthConfiguration{})
	app := provisiontest.NewFakeApp("app-name", "python", 1)
	routertest.FakeRouter.AddBackend(app.GetName())
	defer routertest.FakeRouter.RemoveBackend(app.GetName())
	cont := Container{
		Name:    "myName",
		AppName: app.GetName(),
		Type:    app.GetPlatform(),
		Status:  "created",
	}
	err := cont.Create(&CreateArgs{
		App:         app,
		ImageID:     img,
		Commands:    []string{"docker", "run"},
		Provisioner: s.p,
	})
	c.Assert(err, check.IsNil)
	defer s.removeTestContainer(&cont)
	dcli, _ := docker.NewClient(s.server.URL())
	container, err := dcli.InspectContainer(cont.ID)
	c.Assert(err, check.IsNil)
	c.Assert(container.Config.User, check.Equals, "")
}
开发者ID:kgrvamsi,项目名称:tsuru,代码行数:28,代码来源:container_test.go


示例18: TestCheckBeanstalkdNoQueueConfigured

func (s *CheckerSuite) TestCheckBeanstalkdNoQueueConfigured(c *check.C) {
	old, _ := config.Get("queue")
	defer config.Set("queue", old)
	config.Unset("queue")
	err := checkBeanstalkd()
	c.Assert(err, check.IsNil)
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:7,代码来源:checker_test.go


示例19: BuildHealthCheck

// BuildHealthCheck creates a healthcheck function for the given providerName.
//
// It will call the HealthCheck() method in the provider (only if it's also a
// HealthChecker), for each instance of it (including the "main" instance and
// all custom IaaSes).
func BuildHealthCheck(providerName string) func() error {
	return func() error {
		iaasConfig, err := config.Get("iaas")
		if err != nil {
			return hc.ErrDisabledComponent
		}
		iaases, _ := iaasConfig.(map[interface{}]interface{})
		for ifaceName := range iaases {
			name := ifaceName.(string)
			if name == "custom" {
				customIaases := iaases[name].(map[interface{}]interface{})
				for ifaceName := range customIaases {
					iaas := customIaases[ifaceName.(string)].(map[interface{}]interface{})
					if iaas["provider"].(string) != providerName {
						continue
					}
					name = ifaceName.(string)
				}
			} else if name != providerName {
				continue
			}
			err := healthCheck(name)
			if err != nil {
				return err
			}
		}
		return nil
	}
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:34,代码来源:hc.go


示例20: TestHealthCheckDockerRegistryV2TLS

func (s *S) TestHealthCheckDockerRegistryV2TLS(c *check.C) {
	var request *http.Request
	server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		request = r
		w.Write([]byte("{}"))
	}))
	defer server.Close()
	oldTransport := tsuruNet.Dial5Full60ClientNoKeepAlive.Transport
	defer func() { tsuruNet.Dial5Full60ClientNoKeepAlive.Transport = oldTransport }()
	tsuruNet.Dial5Full60ClientNoKeepAlive.Transport = &http.Transport{
		TLSClientConfig: &tls.Config{
			InsecureSkipVerify: true,
		},
	}
	if old, err := config.Get("docker:registry"); err == nil {
		defer config.Set("docker:registry", old)
	} else {
		defer config.Unset("docker:registry")
	}
	config.Set("docker:registry", server.URL+"/")
	err := healthCheckDockerRegistry()
	c.Assert(err, check.IsNil)
	c.Assert(request.URL.Path, check.Equals, "/v2/")
	c.Assert(request.Method, check.Equals, "GET")
}
开发者ID:tsuru,项目名称:tsuru,代码行数:25,代码来源:hc_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang config.GetBool函数代码示例发布时间:2022-05-28
下一篇:
Golang commandmocker.Remove函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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