本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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"})
}
示例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")
}
示例12: WebProcessDefaultPort
func WebProcessDefaultPort() string {
port, err := config.Get("docker:run-cmd:port")
if err != nil {
return "8888"
}
return fmt.Sprint(port)
}
示例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)
}
示例14: getPort
func getPort() (string, error) {
port, err := config.Get("docker:run-cmd:port")
if err != nil {
return "", err
}
return fmt.Sprint(port), nil
}
示例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
}
}