本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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),
}
}
示例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))
}
示例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
}
示例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)
}
}
示例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)
}
}
示例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()
}
示例14: getBsSysLogPort
func getBsSysLogPort() int {
bsPort, _ := config.GetInt("docker:bs:syslog-port")
if bsPort == 0 {
bsPort = 1514
}
return bsPort
}
示例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)
}
}