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


Golang strconv.ParseUint函数代码示例

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


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

示例1: Start

func (d *UDPClient) Start(uri *url.URL) error {
	d.url = uri
	d.stop = make(chan struct{})

	params := uri.Query()
	// The address must not have a port, as otherwise both announce and lookup
	// sockets would try to bind to the same port.
	addr, err := net.ResolveUDPAddr(d.url.Scheme, params.Get("listenaddress")+":0")
	if err != nil {
		return err
	}
	d.listenAddress = addr

	broadcastSeconds, err := strconv.ParseUint(params.Get("broadcast"), 0, 0)
	if err != nil {
		d.globalBroadcastInterval = DefaultGlobalBroadcastInterval
	} else {
		d.globalBroadcastInterval = time.Duration(broadcastSeconds) * time.Second
	}

	retrySeconds, err := strconv.ParseUint(params.Get("retry"), 0, 0)
	if err != nil {
		d.errorRetryInterval = DefaultErrorRetryInternval
	} else {
		d.errorRetryInterval = time.Duration(retrySeconds) * time.Second
	}

	d.wg.Add(1)
	go d.broadcast()
	return nil
}
开发者ID:KFDCompiled,项目名称:syncthing,代码行数:31,代码来源:client_udp.go

示例2: branchesBehindAhead

// branchesBehindAhead returns the behind/ahead commit counts information for branch, against base branch.
func (r *Repository) branchesBehindAhead(branch, base string) (*vcs.BehindAhead, error) {
	if err := checkSpecArgSafety(branch); err != nil {
		return nil, err
	}
	if err := checkSpecArgSafety(base); err != nil {
		return nil, err
	}

	cmd := exec.Command("git", "rev-list", "--count", "--left-right", fmt.Sprintf("refs/heads/%s...refs/heads/%s", base, branch))
	cmd.Dir = r.Dir
	out, err := cmd.Output()
	if err != nil {
		return nil, err
	}
	behindAhead := strings.Split(strings.TrimSuffix(string(out), "\n"), "\t")
	b, err := strconv.ParseUint(behindAhead[0], 10, 0)
	if err != nil {
		return nil, err
	}
	a, err := strconv.ParseUint(behindAhead[1], 10, 0)
	if err != nil {
		return nil, err
	}
	return &vcs.BehindAhead{Behind: uint32(b), Ahead: uint32(a)}, nil
}
开发者ID:emil2k,项目名称:go-vcs,代码行数:26,代码来源:repo.go

示例3: parseCPUStat

func parseCPUStat(usage, statContents string) (stat garden.ContainerCPUStat) {
	cpuUsage, err := strconv.ParseUint(strings.Trim(usage, "\n"), 10, 0)
	if err != nil {
		return
	}

	stat.Usage = cpuUsage

	scanner := bufio.NewScanner(strings.NewReader(statContents))

	scanner.Split(bufio.ScanWords)

	for scanner.Scan() {
		field := scanner.Text()

		if !scanner.Scan() {
			break
		}

		value, err := strconv.ParseUint(scanner.Text(), 10, 0)
		if err != nil {
			continue
		}

		switch field {
		case "user":
			stat.User = value
		case "system":
			stat.System = value
		}
	}

	return
}
开发者ID:nagyistoce,项目名称:garden-linux,代码行数:34,代码来源:metrics.go

示例4: getActivity

func (ctl *controller) getActivity(c web.C, w http.ResponseWriter, r *http.Request) {
	teamID, _ := c.Env["team_id"].(string)

	p := api.ActivityQueryParams{
		AppID:      r.URL.Query().Get("app"),
		GroupID:    r.URL.Query().Get("group"),
		ChannelID:  r.URL.Query().Get("channel"),
		InstanceID: r.URL.Query().Get("instance"),
		Version:    r.URL.Query().Get("version"),
	}
	p.Severity, _ = strconv.Atoi(r.URL.Query().Get("severity"))
	p.Start, _ = time.Parse(time.RFC3339, r.URL.Query().Get("start"))
	p.End, _ = time.Parse(time.RFC3339, r.URL.Query().Get("end"))
	p.Page, _ = strconv.ParseUint(r.URL.Query().Get("page"), 10, 64)
	p.PerPage, _ = strconv.ParseUint(r.URL.Query().Get("perpage"), 10, 64)

	activityEntriesJSON, err := ctl.api.GetActivityJSON(teamID, p)
	switch err {
	case nil:
		w.Write(activityEntriesJSON)
	case sql.ErrNoRows:
		w.Write([]byte(`[]`))
	default:
		logger.Error("getActivity", "error", err, "teamID", teamID, "p", p)
		http.Error(w, http.StatusText(400), 400)
	}
}
开发者ID:dpatel06,项目名称:coreroller,代码行数:27,代码来源:controller.go

示例5: parseYencHeader

func (p *Part) parseYencHeader(line string) {
	pairs := p.getKeyValuePairs(line)
	for key, value := range pairs {
		switch key {
		case "part":
			if i, e := strconv.ParseUint(value, 10, 32); e == nil {
				p.Part = uint32(i)
			}
		case "total":
			if i, e := strconv.ParseUint(value, 10, 32); e == nil {
				p.Total = uint32(i)
			}
		case "line":
			if i, e := strconv.ParseUint(value, 10, 32); e == nil {
				p.LineSize = uint32(i)
			}
		case "size":
			if i, e := strconv.ParseUint(value, 10, 32); e == nil {
				p.TotalSize = uint32(i)
			}
		case "name":
			p.Name = value
		}
	}
}
开发者ID:strider-,项目名称:go-usenet,代码行数:25,代码来源:yenc.go

示例6: runAs

// runAs takes a user id as a string and looks up the user, and sets the command
// to execute as that user.
func (e *UniversalExecutor) runAs(userid string) error {
	u, err := user.Lookup(userid)
	if err != nil {
		return fmt.Errorf("Failed to identify user %v: %v", userid, err)
	}

	// Convert the uid and gid
	uid, err := strconv.ParseUint(u.Uid, 10, 32)
	if err != nil {
		return fmt.Errorf("Unable to convert userid to uint32: %s", err)
	}
	gid, err := strconv.ParseUint(u.Gid, 10, 32)
	if err != nil {
		return fmt.Errorf("Unable to convert groupid to uint32: %s", err)
	}

	// Set the command to run as that user and group.
	if e.cmd.SysProcAttr == nil {
		e.cmd.SysProcAttr = &syscall.SysProcAttr{}
	}
	if e.cmd.SysProcAttr.Credential == nil {
		e.cmd.SysProcAttr.Credential = &syscall.Credential{}
	}
	e.cmd.SysProcAttr.Credential.Uid = uint32(uid)
	e.cmd.SysProcAttr.Credential.Gid = uint32(gid)

	return nil
}
开发者ID:zanella,项目名称:nomad,代码行数:30,代码来源:executor_linux.go

示例7: Set

func (h *HTTPHashFilters) Set(value string) error {
	valArr := strings.SplitN(value, ":", 2)
	if len(valArr) < 2 {
		return errors.New("need both header and value, colon-delimited (ex. user_id:50%)")
	}

	f := hashFilter{name: []byte(valArr[0])}

	val := strings.TrimSpace(valArr[1])

	if strings.Contains(val, "%") {
		p, _ := strconv.ParseInt(val[:len(val)-1], 0, 0)
		f.percent = uint32(p)
	} else if strings.Contains(val, "/") {
		// DEPRECATED format
		var num, den uint64

		fracArr := strings.Split(val, "/")
		num, _ = strconv.ParseUint(fracArr[0], 10, 64)
		den, _ = strconv.ParseUint(fracArr[1], 10, 64)

		f.percent = uint32((float64(num) / float64(den)) * 100)
	} else {
		return errors.New("Value should be percent and contain '%'")
	}

	*h = append(*h, f)

	return nil
}
开发者ID:buger,项目名称:gor,代码行数:30,代码来源:http_modifier_settings.go

示例8: Set

func (s *GeneralStats) Set(key string, value []byte) error {
	reflectValue := reflect.ValueOf(s).Elem()
	reflectField := reflectValue.FieldByName(snake2Camel(key))
	switch reflectField.Kind() {
	case reflect.Uint32:
		i, err := strconv.ParseUint(string(value), 10, 32)
		if err != nil {
			return err
		}
		reflectField.SetUint(i)
	case reflect.Uint64:
		i, err := strconv.ParseUint(string(value), 10, 64)
		if err != nil {
			return err
		}
		reflectField.SetUint(i)
	case reflect.Float64:
		i, err := strconv.ParseFloat(string(value), 64)
		if err != nil {
			return err
		}
		reflectField.SetFloat(i)
	case reflect.Bool:
		i, err := strconv.ParseBool(string(value))
		if err != nil {
			return err
		}
		reflectField.SetBool(i)
	case reflect.String:
		reflectField.SetString(string(value))
	default:
		return ErrInvalidStatsKey
	}
	return nil
}
开发者ID:qmdx,项目名称:gomemcache,代码行数:35,代码来源:memcache.go

示例9: MyUserAndGroup

// Return the UID and GID of this process.
func MyUserAndGroup() (uid uint32, gid uint32, err error) {
	// Ask for the current user.
	user, err := user.Current()
	if err != nil {
		panic(err)
	}

	// Parse UID.
	uid64, err := strconv.ParseUint(user.Uid, 10, 32)
	if err != nil {
		err = fmt.Errorf("Parsing UID (%s): %v", user.Uid, err)
		return
	}

	// Parse GID.
	gid64, err := strconv.ParseUint(user.Gid, 10, 32)
	if err != nil {
		err = fmt.Errorf("Parsing GID (%s): %v", user.Gid, err)
		return
	}

	uid = uint32(uid64)
	gid = uint32(gid64)

	return
}
开发者ID:mbookman,项目名称:gcsfuse,代码行数:27,代码来源:perms.go

示例10: parseTrailer

func (d *decoder) parseTrailer(line string) error {
	// split on space for headers
	parts := strings.Split(line, " ")
	for i, _ := range parts {
		kv := strings.Split(strings.TrimSpace(parts[i]), "=")
		if len(kv) < 2 {
			continue
		}
		switch kv[0] {
		case "size":
			d.part.Size, _ = strconv.ParseInt(kv[1], 10, 64)
		case "pcrc32":
			if crc64, err := strconv.ParseUint(kv[1], 16, 64); err == nil {
				d.part.crc32 = uint32(crc64)
			}
		case "crc32":
			if crc64, err := strconv.ParseUint(kv[1], 16, 64); err == nil {
				d.crc32 = uint32(crc64)
			}
		case "part":
			partNum, _ := strconv.Atoi(kv[1])
			if partNum != d.part.Number {
				return fmt.Errorf("yenc: =yend header out of order expected part %d got %d", d.part.Number, partNum)
			}
		}
	}
	return nil
}
开发者ID:dominikh,项目名称:yenc,代码行数:28,代码来源:yenc.go

示例11: ParseMariadbGTIDSet

// We don't support multi source replication, so the mariadb gtid set may have only domain-server-sequence
func ParseMariadbGTIDSet(str string) (GTIDSet, error) {
	if len(str) == 0 {
		return MariadbGTID{0, 0, 0}, nil
	}

	seps := strings.Split(str, "-")

	var gtid MariadbGTID

	if len(seps) != 3 {
		return gtid, errors.Errorf("invalid Mariadb GTID %v, must domain-server-sequence", str)
	}

	domainID, err := strconv.ParseUint(seps[0], 10, 32)
	if err != nil {
		return gtid, errors.Errorf("invalid MariaDB GTID Domain ID (%v): %v", seps[0], err)
	}

	serverID, err := strconv.ParseUint(seps[1], 10, 32)
	if err != nil {
		return gtid, errors.Errorf("invalid MariaDB GTID Server ID (%v): %v", seps[1], err)
	}

	sequenceID, err := strconv.ParseUint(seps[2], 10, 64)
	if err != nil {
		return gtid, errors.Errorf("invalid MariaDB GTID Sequence number (%v): %v", seps[2], err)
	}

	return MariadbGTID{
		DomainID:       uint32(domainID),
		ServerID:       uint32(serverID),
		SequenceNumber: sequenceID}, nil
}
开发者ID:ZhiephieCook,项目名称:gh-ost,代码行数:34,代码来源:mariadb_gtid.go

示例12: stringValue

func stringValue(s string, fieldVal interface{}) error {
	var err error

	switch v := fieldVal.(type) {
	case *bool:
		*v, err = strconv.ParseBool(s)
	case *string:
		*v = s
	case *[]byte:
		*v = []byte(s)
	case *int:
		*v, err = strconv.Atoi(s)
	case *int64:
		*v, err = strconv.ParseInt(s, 10, 64)
	case *uint:
		var a uint64
		a, err = strconv.ParseUint(s, 10, 32)
		*v = uint(a)
	case *uint64:
		*v, err = strconv.ParseUint(s, 10, 64)
	case *float64:
		*v, err = strconv.ParseFloat(s, 64)
	case *time.Duration:
		*v, err = time.ParseDuration(s)
	default:
		return fmt.Errorf("unhandled parameter type %T", fieldVal)
	}

	return err
}
开发者ID:moshee,项目名称:gas,代码行数:30,代码来源:envconf.go

示例13: isValid

// if the raft algorithm making progress in leader, if not, the leader is isolated from cluster
func isValid(tr *http.Transport, ep string) bool {
	httpclient := http.Client{
		Transport: tr,
	}
	// we only need the header of response
	resp0, err := httpclient.Head(ep + "/v2/keys")
	if err != nil {
		return false
	}
	rt0, err1 := strconv.ParseUint(resp0.Header.Get("X-Raft-Term"), 10, 64)
	ri0, err2 := strconv.ParseUint(resp0.Header.Get("X-Raft-Index"), 10, 64)
	if err1 != nil || err2 != nil {
		return false
	}

	time.Sleep(time.Second)
	// we only need the header of response
	resp1, err := httpclient.Head(ep + "/v2/keys")
	if err != nil {
		return false
	}
	rt1, err1 := strconv.ParseUint(resp1.Header.Get("X-Raft-Term"), 10, 64)
	ri1, err2 := strconv.ParseUint(resp1.Header.Get("X-Raft-Index"), 10, 64)
	if err1 != nil || err2 != nil {
		return false
	}

	// raft algorithm doesn't make progress, leader is invalid
	if rt0 != rt1 || ri0 == ri1 {
		return false
	}
	return true
}
开发者ID:combk8s,项目名称:go-etcd,代码行数:34,代码来源:client.go

示例14: parseMariadbGTID

// parseMariadbGTID is registered as a GTID parser.
func parseMariadbGTID(s string) (GTID, error) {
	// Split into parts.
	parts := strings.Split(s, "-")
	if len(parts) != 3 {
		return nil, fmt.Errorf("invalid MariaDB GTID (%v): expecting Domain-Server-Sequence", s)
	}

	// Parse Domain ID.
	Domain, err := strconv.ParseUint(parts[0], 10, 32)
	if err != nil {
		return nil, fmt.Errorf("invalid MariaDB GTID Domain ID (%v): %v", parts[0], err)
	}

	// Parse Server ID.
	Server, err := strconv.ParseUint(parts[1], 10, 32)
	if err != nil {
		return nil, fmt.Errorf("invalid MariaDB GTID Server ID (%v): %v", parts[1], err)
	}

	// Parse Sequence number.
	Sequence, err := strconv.ParseUint(parts[2], 10, 64)
	if err != nil {
		return nil, fmt.Errorf("invalid MariaDB GTID Sequence number (%v): %v", parts[2], err)
	}

	return MariadbGTID{
		Domain:   uint32(Domain),
		Server:   uint32(Server),
		Sequence: Sequence,
	}, nil
}
开发者ID:CowLeo,项目名称:vitess,代码行数:32,代码来源:mariadb_gtid.go

示例15: parseStats

func (p PlackPlugin) parseStats(body io.Reader) (map[string]interface{}, error) {
	stat := make(map[string]interface{})
	decoder := json.NewDecoder(body)

	var s PlackServerStatus
	err := decoder.Decode(&s)
	if err != nil {
		return nil, err
	}

	stat["busy_workers"], err = strconv.ParseFloat(s.BusyWorkers, 64)
	if err != nil {
		return nil, errors.New("cannot get values")
	}

	stat["idle_workers"], err = strconv.ParseFloat(s.IdleWorkers, 64)
	if err != nil {
		return nil, errors.New("cannot get values")
	}

	stat["requests"], err = strconv.ParseUint(s.TotalAccesses, 10, 64)
	if err != nil {
		return nil, errors.New("cannot get values")
	}

	stat["bytes_sent"], err = strconv.ParseUint(s.TotalKbytes, 10, 64)
	if err != nil {
		return nil, errors.New("cannot get values")
	}
	return stat, nil
}
开发者ID:supercaracal,项目名称:mackerel-agent-plugins,代码行数:31,代码来源:plack.go


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