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


Golang config.GetInt函数代码示例

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


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

示例1: dial

func (factory *redismqQFactory) dial() (redis.Conn, error) {
	host, err := config.GetString("redis-queue:host")
	if err != nil {
		host = "localhost"
	}
	port, err := config.GetString("redis-queue:port")
	if err != nil {
		if nport, err := config.GetInt("redis-queue:port"); err != nil {
			port = "6379"
		} else {
			port = fmt.Sprintf("%d", nport)
		}
	}
	password, _ := config.GetString("redis-queue:password")
	db, err := config.GetInt("redis-queue:db")
	if err != nil {
		db = 3
	}
	conn, err := redis.Dial("tcp", host+":"+port)
	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:tomzhang,项目名称:golang-devops-stuff,代码行数:31,代码来源:redismq.go

示例2: get

func (redismqQFactory) get(name, consumerName string) (*redismqQ, error) {
	host, err := config.GetString("redis-queue:host")
	if err != nil {
		host = "localhost"
	}
	port, err := config.GetString("redis-queue:port")
	if err != nil {
		if nport, err := config.GetInt("redis-queue:port"); err != nil {
			port = "6379"
		} else {
			port = fmt.Sprintf("%d", nport)
		}
	}
	password, _ := config.GetString("redis-queue:password")
	db, err := config.GetInt("redis-queue:db")
	if err != nil {
		db = 3
	}
	queue := redismq.CreateQueue(host, port, password, int64(db), name)
	consumer, err := queue.AddConsumer(consumerName)
	if err != nil {
		return nil, err
	}
	return &redismqQ{name: name, queue: queue, consumer: consumer}, nil
}
开发者ID:rpeterson,项目名称:tsuru,代码行数:25,代码来源:redismq.go

示例3: getPool

func (factory *redisPubSubFactory) getPool() *redis.Pool {
	factory.Lock()
	defer factory.Unlock()
	if factory.pool != nil {
		return factory.pool
	}
	maxIdle, err := config.GetInt("pubsub:pool-max-idle-conn")
	if err != nil {
		maxIdle, err = config.GetInt("redis-queue:pool-max-idle-conn")
		if err != nil {
			maxIdle = 20
		}
	}
	idleTimeout, err := config.GetInt("pubsub:pool-idle-timeout")
	if err != nil {
		idleTimeout, err = config.GetInt("redis-queue:pool-idle-timeout")
		if err != nil {
			idleTimeout = 300
		}
	}
	factory.pool = &redis.Pool{
		MaxIdle:     maxIdle,
		IdleTimeout: time.Duration(idleTimeout) * time.Second,
		Dial:        factory.dial,
	}
	return factory.pool
}
开发者ID:Lh4cKg,项目名称:tsuru,代码行数:27,代码来源:redismq.go

示例4: Initialize

func Initialize() (*NodeHealer, error) {
	if HealerInstance != nil {
		return nil, errors.New("healer alread initialized")
	}
	autoHealingNodes, err := config.GetBool("docker:healing:heal-nodes")
	if err != nil {
		autoHealingNodes = true
	}
	if !autoHealingNodes {
		return nil, nil
	}
	disabledSeconds, _ := config.GetInt("docker:healing:disabled-time")
	if disabledSeconds <= 0 {
		disabledSeconds = 30
	}
	maxFailures, _ := config.GetInt("docker:healing:max-failures")
	if maxFailures <= 0 {
		maxFailures = 5
	}
	waitSecondsNewMachine, _ := config.GetInt("docker:healing:wait-new-time")
	if waitSecondsNewMachine <= 0 {
		waitSecondsNewMachine = 5 * 60
	}
	HealerInstance = newNodeHealer(nodeHealerArgs{
		DisabledTime:          time.Duration(disabledSeconds) * time.Second,
		WaitTimeNewMachine:    time.Duration(waitSecondsNewMachine) * time.Second,
		FailuresBeforeHealing: maxFailures,
	})
	shutdown.Register(HealerInstance)
	return HealerInstance, nil
}
开发者ID:tsuru,项目名称:tsuru,代码行数:31,代码来源:healer.go

示例5: DefaultPlan

func DefaultPlan() (*Plan, error) {
	conn, err := db.Conn()
	if err != nil {
		return nil, err
	}
	defer conn.Close()
	var plans []Plan
	err = conn.Plans().Find(bson.M{"default": true}).All(&plans)
	if err != nil {
		return nil, err
	}
	if len(plans) == 0 {
		// For backard compatibility only, this fallback will be removed. You
		// should have at least one plan configured.
		configMemory, _ := config.GetInt("docker:memory")
		configSwap, _ := config.GetInt("docker:swap")
		return &Plan{
			Name:     "autogenerated",
			Memory:   int64(configMemory) * 1024 * 1024,
			Swap:     int64(configSwap-configMemory) * 1024 * 1024,
			CpuShare: 100,
		}, nil
	}
	if len(plans) > 1 {
		return nil, ErrPlanDefaultAmbiguous
	}
	return &plans[0], nil
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:28,代码来源:plan.go

示例6: 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

示例7: readConfig

func readConfig(path string) (Config, error) {
	cfg := Config{}
	configFile := filepath.Join(path, "config.yaml")

	err := config.ReadConfigFile(configFile)
	if err != nil {
		return cfg, err
	}

	cfg.Id, err = config.GetString("id")
	if err != nil {
		return cfg, err
	}

	cfg.Hostname, err = config.GetString("hostname")
	if err != nil {
		return cfg, err
	}

	cfg.DiskPath = filepath.Join(path, "disk.qcow")
	cfg.Disk, err = config.GetInt("disk")
	if err != nil {
		return cfg, err
	}

	cfg.Cpu, err = config.GetInt("cpu")
	if err != nil {
		return cfg, err
	}

	cfg.Memory, err = config.GetInt("memory")
	if err != nil {
		return cfg, err
	}

	cfg.DNS, err = config.GetString("dns")
	if err != nil {
		return cfg, err
	}

	cfg.Docker, err = config.GetString("docker")
	if err != nil {
		return cfg, err
	}

	cfg.Extra, err = config.GetString("extra")
	if err != nil {
		return cfg, err
	}

	cfg.Route, err = config.GetBool("route")
	return cfg, err
}
开发者ID:nlf,项目名称:dlite,代码行数:53,代码来源:config.go

示例8: initAutoScaleConfig

func (p *dockerProvisioner) initAutoScaleConfig() *autoScaleConfig {
	enabled, _ := config.GetBool("docker:auto-scale:enabled")
	waitSecondsNewMachine, _ := config.GetInt("docker:auto-scale:wait-new-time")
	runInterval, _ := config.GetInt("docker:auto-scale:run-interval")
	TotalMemoryMetadata, _ := config.GetString("docker:scheduler:total-memory-metadata")
	return &autoScaleConfig{
		TotalMemoryMetadata: TotalMemoryMetadata,
		WaitTimeNewMachine:  time.Duration(waitSecondsNewMachine) * time.Second,
		RunInterval:         time.Duration(runInterval) * time.Second,
		Enabled:             enabled,
		provisioner:         p,
		done:                make(chan bool),
	}
}
开发者ID:tsuru,项目名称:tsuru,代码行数:14,代码来源:provisioner.go

示例9: postnetwork

func postnetwork(container *global.Container, ip string) {
	gulpPort, _ := config.GetInt("docker:gulp_port")

	url := "http://" + container.SwarmNode + ":" + strconv.Itoa(gulpPort) + "/docker/networks"
	log.Info("URL:> %s", url)

	bridge, _ := config.GetString("docker:bridge")
	gateway, _ := config.GetString("docker:gateway")

	data := &global.DockerNetworksInfo{Bridge: bridge, ContainerId: container.ContainerID, IpAddr: ip, Gateway: gateway}
	res2B, _ := json.Marshal(data)
	req, err := http.NewRequest("POST", url, bytes.NewBuffer(res2B))
	req.Header.Set("X-Custom-Header", "myvalue")
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		log.Error("gulpd client was failed : %s", err)
	}
	defer resp.Body.Close()

	log.Info("response Status : %s", resp.Status)
	log.Info("response Headers : %s", resp.Header)
	body, _ := ioutil.ReadAll(resp.Body)
	log.Info("response Body : %s", string(body))
}
开发者ID:LogeshEswar,项目名称:megamd,代码行数:27,代码来源:utils.go

示例10: Create

func (u *User) Create() error {
	conn, err := db.Conn()
	if err != nil {
		return err
	}
	defer conn.Close()
	if u.Quota.Limit == 0 {
		u.Quota = quota.Unlimited
		var limit int
		if limit, err = config.GetInt("quota:apps-per-user"); err == nil && limit > -1 {
			u.Quota.Limit = limit
		}
	}
	err = conn.Users().Insert(u)
	if err != nil {
		return err
	}
	err = u.createOnRepositoryManager()
	if err != nil {
		u.Delete()
		return err
	}
	err = u.AddRolesForEvent(permission.RoleEventUserCreate, "")
	if err != nil {
		log.Errorf("unable to add default roles during user creation for %q: %s", u.Email, err)
	}
	return nil
}
开发者ID:pedrosnk,项目名称:tsuru,代码行数:28,代码来源:user.go

示例11: Run

// Run is the function that starts the collector. The dryMode parameter
// indicates whether the collector should loop forever or not.
//
// It assumes the configuration has already been defined (from a config file or
// memory).
func Run(dryMode bool) {
	log.Init()
	connString, err := config.GetString("database:url")
	if err != nil {
		connString = db.DefaultDatabaseURL
	}
	dbName, err := config.GetString("database:name")
	if err != nil {
		dbName = db.DefaultDatabaseName
	}

	fmt.Printf("Using the database %q from the server %q.\n\n", dbName, connString)
	if !dryMode {
		provisioner, err := config.GetString("provisioner")
		if err != nil {
			fmt.Println("Warning: configuration didn't declare a provisioner, using default provisioner.")
			provisioner = "juju"
		}
		app.Provisioner, err = provision.Get(provisioner)
		if err != nil {
			fatal(err)
		}
		fmt.Printf("Using %q provisioner.\n\n", provisioner)

		timer, err := config.GetInt("collector:ticker-time")
		if err != nil {
			timer = 60
		}
		ticker := time.Tick(time.Duration(timer) * time.Second)
		fmt.Println("tsuru collector agent started...")
		collect(ticker)
	}
}
开发者ID:rpeterson,项目名称:tsuru,代码行数:38,代码来源:runner.go

示例12: waitDocker

func (t *runBs) waitDocker(client *docker.Client) error {
	timeout, _ := config.GetInt("docker:api-timeout")
	if timeout == 0 {
		timeout = 600
	}
	timeoutChan := time.After(time.Duration(timeout) * time.Second)
	pong := make(chan error, 1)
	exit := make(chan struct{})
	go func() {
		for {
			err := client.Ping()
			if err == nil {
				pong <- nil
				return
			}
			if e, ok := err.(*docker.Error); ok && e.Status > 499 {
				pong <- err
				return
			}
			select {
			case <-exit:
				return
			case <-time.After(time.Second):
			}
		}
	}()
	select {
	case err := <-pong:
		return err
	case <-timeoutChan:
		close(exit)
		return errors.Errorf("Docker API at %q didn't respond after %d seconds", client.Endpoint(), timeout)
	}
}
开发者ID:tsuru,项目名称:tsuru,代码行数:34,代码来源:queue.go

示例13: connect

func (r *hipacheRouter) connect() redis.Conn {
	r.Lock()
	defer r.Unlock()
	if r.pool == nil {
		srv := r.redisServer()
		r.pool = &redis.Pool{
			Dial: func() (redis.Conn, error) {
				conn, err := redis.Dial("tcp", srv)
				if err != nil {
					return nil, err
				}
				password, _ := config.GetString(r.prefix + ":redis-password")
				if password != "" {
					_, err = conn.Do("AUTH", password)
					if err != nil {
						return nil, err
					}
				}
				db, err := config.GetInt(r.prefix + ":redis-db")
				if err == nil {
					_, err = conn.Do("SELECT", db)
					if err != nil {
						return nil, err
					}
				}
				return conn, nil
			},
			MaxIdle:     10,
			IdleTimeout: 180e9,
		}
	}
	return r.pool.Get()
}
开发者ID:nicolas2bonfils,项目名称:tsuru,代码行数:33,代码来源:router.go

示例14: getBsSysLogPort

func getBsSysLogPort() int {
	bsPort, _ := config.GetInt("docker:bs:syslog-port")
	if bsPort == 0 {
		bsPort = 1514
	}
	return bsPort
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:7,代码来源:queue_task.go

示例15: waitDocker

func (runBs) waitDocker(endpoint string) error {
	client, err := docker.NewClient(endpoint)
	if err != nil {
		return err
	}
	timeout, _ := config.GetInt("docker:api-timeout")
	if timeout == 0 {
		timeout = 600
	}
	timeoutChan := time.After(time.Duration(timeout) * time.Second)
	pong := make(chan error, 1)
	go func() {
		for {
			err := client.Ping()
			if err == nil {
				pong <- nil
				return
			}
			if e, ok := err.(*docker.Error); ok && e.Status > 499 {
				pong <- err
				return
			}
		}
	}()
	select {
	case err := <-pong:
		return err
	case <-timeoutChan:
		return fmt.Errorf("Docker API at %q didn't respond after %d seconds", endpoint, timeout)
	}
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:31,代码来源:queue_task.go


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