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


Golang strconv.FormatInt函数代码示例

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


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

示例1: Update

// Subscribes a customer to a new plan.
//
// see https://stripe.com/docs/api#update_subscription
func (self *SubscriptionClient) Update(customerId string, params *SubscriptionParams) (*Subscription, error) {
	values := url.Values{"plan": {params.Plan}}

	// set optional parameters
	if len(params.Coupon) != 0 {
		values.Add("coupon", params.Coupon)
	}
	if params.Prorate {
		values.Add("prorate", "true")
	}
	if params.TrialEnd != 0 {
		values.Add("trial_end", strconv.FormatInt(params.TrialEnd, 10))
	}
	if params.Quantity != 0 {
		values.Add("quantity", strconv.FormatInt(params.Quantity, 10))
	}
	// attach a new card, if requested
	if len(params.Token) != 0 {
		values.Add("card", params.Token)
	} else if params.Card != nil {
		appendCardParamsToValues(params.Card, &values)
	}

	s := Subscription{}
	path := "/v1/customers/" + url.QueryEscape(customerId) + "/subscription"
	err := query("POST", path, values, &s)
	return &s, err
}
开发者ID:boj,项目名称:go.stripe,代码行数:31,代码来源:subscription.go

示例2: String

// human friendly version string - major.minor.patch
func (v Version) String() string {
	return strings.Join(([]string{
		strconv.FormatInt(v.Major, BASE10),
		strconv.FormatInt(v.Minor, BASE10),
		strconv.FormatInt(v.Patch, BASE10)}),
		SEPARATOR)
}
开发者ID:elarasu,项目名称:basis,代码行数:8,代码来源:version.go

示例3: joinCpu

func joinCpu(c *configs.Cgroup, pid int) error {
	path, err := getSubsystemPath(c, "cpu")
	if err != nil && !cgroups.IsNotFound(err) {
		return err
	}
	if c.CpuQuota != 0 {
		if err = writeFile(path, "cpu.cfs_quota_us", strconv.FormatInt(c.CpuQuota, 10)); err != nil {
			return err
		}
	}
	if c.CpuPeriod != 0 {
		if err = writeFile(path, "cpu.cfs_period_us", strconv.FormatInt(c.CpuPeriod, 10)); err != nil {
			return err
		}
	}
	if c.CpuRtPeriod != 0 {
		if err = writeFile(path, "cpu.rt_period_us", strconv.FormatInt(c.CpuRtPeriod, 10)); err != nil {
			return err
		}
	}
	if c.CpuRtRuntime != 0 {
		if err = writeFile(path, "cpu.rt_runtime_us", strconv.FormatInt(c.CpuRtRuntime, 10)); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:waterytowers,项目名称:global-hack-day-3,代码行数:28,代码来源:apply_systemd.go

示例4: UpdateAutoScalingGroup

// UpdateAutoScalingGroup updates the scaling group.
//
// To update an auto scaling group with a launch configuration that has the InstanceMonitoring
// flag set to False, you must first ensure that collection of group metrics is disabled.
// Otherwise calls to UpdateAutoScalingGroup will fail.
func (as *AutoScaling) UpdateAutoScalingGroup(ag AutoScalingGroup) (resp *SimpleResp, err error) {
	resp = &SimpleResp{}
	params := makeParams("UpdateAutoScalingGroup")
	params["AutoScalingGroupName"] = ag.AutoScalingGroupName
	addParamsList(params, "AvailabilityZones.member", ag.AvailabilityZones)
	if ag.DefaultCooldown > 0 {
		params["DefaultCooldown"] = strconv.FormatInt(ag.DefaultCooldown, 10)
	}
	params["DesiredCapacity"] = strconv.FormatInt(ag.DesiredCapacity, 10)
	if ag.HealthCheckGracePeriod > 0 {
		params["HealthCheckGracePeriod"] = strconv.FormatInt(ag.HealthCheckGracePeriod, 10)
	}
	if ag.HealthCheckType == "ELB" {
		params["HealthCheckType"] = ag.HealthCheckType
	}
	params["LaunchConfigurationName"] = ag.LaunchConfigurationName
	if ag.MaxSize > 0 {
		params["MaxSize"] = strconv.FormatInt(ag.MaxSize, 10)
	}
	if ag.MinSize > 0 {
		params["MinSize"] = strconv.FormatInt(ag.MinSize, 10)
	}
	if len(ag.TerminationPolicies) > 0 {
		addParamsList(params, "TerminationPolicies.member", ag.TerminationPolicies)
	}
	if len(ag.VPCZoneIdentifier) > 0 {
		params["VPCZoneIdentifier"] = ag.VPCZoneIdentifier
	}
	err = as.query(params, resp)
	if err != nil {
		return nil, err
	}
	return resp, nil
}
开发者ID:docker,项目名称:goamz,代码行数:39,代码来源:autoscaling.go

示例5: newLabels

func newLabels(container *api.Container, pod *api.Pod, restartCount int) map[string]string {
	labels := map[string]string{}
	labels[kubernetesPodNameLabel] = pod.Name
	labels[kubernetesPodNamespaceLabel] = pod.Namespace
	labels[kubernetesPodUIDLabel] = string(pod.UID)
	if pod.DeletionGracePeriodSeconds != nil {
		labels[kubernetesPodDeletionGracePeriodLabel] = strconv.FormatInt(*pod.DeletionGracePeriodSeconds, 10)
	}
	if pod.Spec.TerminationGracePeriodSeconds != nil {
		labels[kubernetesPodTerminationGracePeriodLabel] = strconv.FormatInt(*pod.Spec.TerminationGracePeriodSeconds, 10)
	}

	labels[kubernetesContainerNameLabel] = container.Name
	labels[kubernetesContainerHashLabel] = strconv.FormatUint(kubecontainer.HashContainer(container), 16)
	labels[kubernetesContainerRestartCountLabel] = strconv.Itoa(restartCount)
	labels[kubernetesContainerTerminationMessagePathLabel] = container.TerminationMessagePath
	if container.Lifecycle != nil && container.Lifecycle.PreStop != nil {
		// Using json enconding so that the PreStop handler object is readable after writing as a label
		rawPreStop, err := json.Marshal(container.Lifecycle.PreStop)
		if err != nil {
			glog.Errorf("Unable to marshal lifecycle PreStop handler for container %q of pod %q: %v", container.Name, format.Pod(pod), err)
		} else {
			labels[kubernetesContainerPreStopHandlerLabel] = string(rawPreStop)
		}
	}

	return labels
}
开发者ID:sjtud,项目名称:kubernetes,代码行数:28,代码来源:labels.go

示例6: Inc

func (txn *dbTxn) Inc(k kv.Key, step int64) (int64, error) {
	log.Debugf("Inc %q, step %d txn:%d", k, step, txn.tid)
	k = kv.EncodeKey(k)

	txn.markOrigin(k)
	val, err := txn.UnionStore.Get(k)
	if kv.IsErrNotFound(err) {
		err = txn.UnionStore.Set(k, []byte(strconv.FormatInt(step, 10)))
		if err != nil {
			return 0, errors.Trace(err)
		}

		return step, nil
	}
	if err != nil {
		return 0, errors.Trace(err)
	}

	intVal, err := strconv.ParseInt(string(val), 10, 0)
	if err != nil {
		return intVal, errors.Trace(err)
	}

	intVal += step
	err = txn.UnionStore.Set(k, []byte(strconv.FormatInt(intVal, 10)))
	if err != nil {
		return 0, errors.Trace(err)
	}
	txn.store.compactor.OnSet(k)
	return intVal, nil
}
开发者ID:yzl11,项目名称:vessel,代码行数:31,代码来源:txn.go

示例7: UploadSignedURL

// UploadSignedURL returns a signed URL that allows anyone holding the URL
// to upload the object at path. The signature is valid until expires.
// contenttype is a string like image/png
// path is the resource name in s3 terminalogy like images/ali.png [obviously exclusing the bucket name itself]
func (b *Bucket) UploadSignedURL(path, method, content_type string, expires time.Time) string {
	expire_date := expires.Unix()
	if method != "POST" {
		method = "PUT"
	}
	stringToSign := method + "\n\n" + content_type + "\n" + strconv.FormatInt(expire_date, 10) + "\n/" + b.Name + "/" + path
	fmt.Println("String to sign:\n", stringToSign)
	a := b.S3.Auth
	secretKey := a.SecretKey
	accessId := a.AccessKey
	mac := hmac.New(sha1.New, []byte(secretKey))
	mac.Write([]byte(stringToSign))
	macsum := mac.Sum(nil)
	signature := base64.StdEncoding.EncodeToString([]byte(macsum))
	signature = strings.TrimSpace(signature)

	signedurl, err := url.Parse("https://" + b.Name + ".s3.amazonaws.com/")
	if err != nil {
		log.Println("ERROR sining url for S3 upload", err)
		return ""
	}
	signedurl.Path += path
	params := url.Values{}
	params.Add("AWSAccessKeyId", accessId)
	params.Add("Expires", strconv.FormatInt(expire_date, 10))
	params.Add("Signature", signature)
	if a.Token() != "" {
		params.Add("token", a.Token())
	}

	signedurl.RawQuery = params.Encode()
	return signedurl.String()
}
开发者ID:crash2burn,项目名称:goamz,代码行数:37,代码来源:s3.go

示例8: String

func (q Query) String() string {
	s := q.Aggregator + ":"
	if q.Downsample != "" {
		s += q.Downsample + ":"
	}
	if q.Rate {
		s += "rate"
		if q.RateOptions.Counter {
			s += "{counter"
			if q.RateOptions.CounterMax != 0 {
				s += ","
				s += strconv.FormatInt(q.RateOptions.CounterMax, 10)
			}
			if q.RateOptions.ResetValue != 0 {
				if q.RateOptions.CounterMax == 0 {
					s += ","
				}
				s += ","
				s += strconv.FormatInt(q.RateOptions.ResetValue, 10)
			}
			s += "}"
		}
		s += ":"
	}
	s += q.Metric
	if len(q.Tags) > 0 {
		s += q.Tags.String()
	}
	if len(q.Filters) > 0 {
		s += q.Filters.String()
	}
	return s
}
开发者ID:Skyscanner,项目名称:bosun,代码行数:33,代码来源:tsdb.go

示例9: checkOut

func checkOut() bool {
	value := strconv.FormatInt(int64(linuxSpec.Spec.Process.User.UID), 10)
	job := "Uid"
	resultTag := false
	if checkResult(job, value) {
		resultTag = true
	} else {
		resultTag = false
	}

	value = strconv.FormatInt(int64(linuxSpec.Spec.Process.User.GID), 10)
	job = "Gid"
	if checkResult(job, value) {
		resultTag = true
	} else {
		resultTag = false
	}

	tmpValue := linuxSpec.Spec.Process.User.AdditionalGids
	job = "Groups"
	for _, tv := range tmpValue {
		tvs := strconv.FormatInt(int64(tv), 10)
		if checkResult(job, tvs) {
			resultTag = true
		} else {
			resultTag = false
		}
	}

	return resultTag
}
开发者ID:Issacpeng,项目名称:oct,代码行数:31,代码来源:process.go

示例10: transData

func (hp *HttpProtocol) transData(server string, transData *TransData) (err error) {
	/* compose req */
	uri := hp.regTopic.ReplaceAllString(hp.uri, transData.topic)
	uri = hp.regMethod.ReplaceAllString(uri, transData.method)
	uri = hp.regPartition.ReplaceAllString(uri, strconv.FormatInt(int64(transData.partition), 10))
	uri = hp.regTransid.ReplaceAllString(uri, strconv.FormatInt(transData.transid, 10))
	url := fmt.Sprintf("http://%s%s", server, uri)
	req, err := http.NewRequest("POST", url, bytes.NewReader(transData.data))
	if err != nil {
		logger.Warning("module [%s]: fail to transData: url=%s, topic=%s, partition=%d, transid=%d, method=%s, err=%s", hp.moduleName, url, transData.topic, transData.partition, transData.transid, transData.method, err.Error())
		return err
	}
	/* add header */
	req.Header = hp.header
	req.Host = hp.reqHeaderHost
	/* Post */
	res, err := hp.client.Do(req)
	if err != nil {
		logger.Warning("module [%s]: fail to transData: url=%s, topic=%s, partition=%d, transid=%d, method=%s, err=%s", hp.moduleName, url, transData.topic, transData.partition, transData.transid, transData.method, err.Error())
		return err
	}
	defer res.Body.Close()
	/* check res: 200 不重试;其他,重试 */
	if res.StatusCode == http.StatusOK {
		logger.Notice("module [%s]: success transData: url=%s, topic=%s, partition=%d, transid=%d, method=%s, datalen=%d, http_status_code=%d", hp.moduleName, url, transData.topic, transData.partition, transData.transid, transData.method, len(transData.data), res.StatusCode)
		return nil
	} else {
		logger.Warning("module [%s]: fail to transData: url=%s, topic=%s, partition=%d, transid=%d, method=%s, http_status_code=%d", hp.moduleName, url, transData.topic, transData.partition, transData.transid, transData.method, res.StatusCode)
		return errors.New("fail to trans")
	}
	return nil
}
开发者ID:dzch,项目名称:kafka-http-wrapper,代码行数:32,代码来源:http_protocol.go

示例11: floatString

func (i Int) floatString(verb byte, prec int) string {
	switch verb {
	case 'f', 'F':
		str := strconv.FormatInt(int64(i), 10)
		if prec > 0 {
			str += "." + zeros(prec)
		}
		return str
	case 'e', 'E':
		sign := ""
		if i < 0 {
			sign = "-"
			i = -i
		}
		return eFormat(verb, prec, sign, strconv.FormatInt(int64(i), 10), i.eExponent())
	case 'g', 'G':
		// Exponent is always positive so it's easy.
		if i.eExponent() >= prec {
			// Use e format.
			return i.floatString(verb-2, prec-1)
		}
		// Use f format, but this is just an integer.
		return fmt.Sprintf("%d", int64(i))
	default:
		Errorf("can't handle verb %c for int", verb)
	}
	return ""
}
开发者ID:ghost-dog,项目名称:ivy,代码行数:28,代码来源:int.go

示例12: checkResults

//checkResults checks the results between
func checkResults() string {
	for metric, expected := range expectedValues {
		switch m := metric.(type) {
		case *metrics.Counter:
			val, ok := expected.(uint64)
			if !ok {
				return "unexpected type"
			}
			if m.Get() != val {
				return ("unexpected value - got: " +
					strconv.FormatInt(int64(m.Get()), 10) + " but wanted " + strconv.FormatInt(int64(val), 10))
			}
		case *metrics.Gauge:
			val, ok := expected.(float64)
			if !ok {
				return "unexpected type"
			}
			if m.Get() != val {
				return ("unexpected value - got: " +
					strconv.FormatFloat(float64(m.Get()), 'f', 5, 64) + " but wanted " +
					strconv.FormatFloat(float64(val), 'f', 5, 64))
			}
		}
	}
	return ""
}
开发者ID:njuettner,项目名称:inspect,代码行数:27,代码来源:dbstat_test.go

示例13: ToString

// ToString converts a interface to a string.
func ToString(value interface{}) (string, error) {
	switch v := value.(type) {
	case bool:
		if v {
			return "1", nil
		}
		return "0", nil
	case int:
		return strconv.FormatInt(int64(v), 10), nil
	case int64:
		return strconv.FormatInt(int64(v), 10), nil
	case uint64:
		return strconv.FormatUint(uint64(v), 10), nil
	case float32:
		return strconv.FormatFloat(float64(v), 'f', -1, 32), nil
	case float64:
		return strconv.FormatFloat(float64(v), 'f', -1, 64), nil
	case string:
		return v, nil
	case []byte:
		return string(v), nil
	case mysql.Time:
		return v.String(), nil
	case mysql.Duration:
		return v.String(), nil
	case mysql.Decimal:
		return v.String(), nil
	case mysql.Hex:
		return v.ToString(), nil
	case mysql.Bit:
		return v.ToString(), nil
	default:
		return "", errors.Errorf("cannot convert %v(type %T) to string", value, value)
	}
}
开发者ID:nengwang,项目名称:tidb,代码行数:36,代码来源:convert.go

示例14: save

func (dir *Directory) save(i int64, l [][]string) error {
	b := new(bytes.Buffer)
	w := csv.NewWriter(b)
	w.WriteAll(l)
	w.Flush()

	// done!

	part := strconv.FormatInt(i, 10) + "."
	p, e := LoadDPs(dir.R, part)
	if e != nil {
		p = new(DirPage)
		e = nil
	}
	p.Version = (p.Version + 1) % 8
	e = SaveDPs(dir.R, p, part)
	if e != nil {
		return e
	}
	pver := part + strconv.FormatInt(p.Version, 10)
	f, e := dir.R.Create(pver)
	if e != nil {
		return e
	}
	defer f.Close()
	e = f.Truncate(int64(b.Len()))
	if e != nil {
		return e
	}
	_, e = f.WriteAt(b.Bytes(), 0)
	return e
}
开发者ID:maxymania,项目名称:metaclusterfs,代码行数:32,代码来源:directory.go

示例15: CoerceString

// Coerce types (string,int,int64, float, []byte) into String type
func CoerceString(v interface{}) (string, error) {
	switch val := v.(type) {
	case string:
		if val == "null" || val == "NULL" {
			return "", nil
		}
		return val, nil
	case int:
		return strconv.Itoa(val), nil
	case int32:
		return strconv.FormatInt(int64(val), 10), nil
	case int64:
		return strconv.FormatInt(val, 10), nil
	case uint32:
		return strconv.FormatUint(uint64(val), 10), nil
	case uint64:
		return strconv.FormatUint(val, 10), nil
	case float32:
		return strconv.FormatFloat(float64(val), 'f', -1, 32), nil
	case float64:
		return strconv.FormatFloat(val, 'f', -1, 64), nil
	case []byte:
		if string(val) == "null" || string(val) == "NULL" {
			return "", nil
		}
		return string(val), nil
	case json.RawMessage:
		if string(val) == "null" || string(val) == "NULL" {
			return "", nil
		}
		return string(val), nil
	}
	return "", fmt.Errorf("Could not coerce to string: %v", v)
}
开发者ID:albertzak,项目名称:transporter,代码行数:35,代码来源:coerce.go


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