當前位置: 首頁>>代碼示例>>Golang>>正文


Golang strconv.Atoui64函數代碼示例

本文整理匯總了Golang中strconv.Atoui64函數的典型用法代碼示例。如果您正苦於以下問題:Golang Atoui64函數的具體用法?Golang Atoui64怎麽用?Golang Atoui64使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Atoui64函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: parse

/* parse a storage command parameters and read the related data
   returns a flag indicating sucesss */
func (self *StorageCommand) parse(line []string) bool {
	var flags, exptime, bytes, casuniq uint64
	var err os.Error
	if len(line) < 5 {
		return Error(self.session, ClientError, "Bad storage command: missing parameters")
	} else if flags, err = strconv.Atoui64(line[2]); err != nil {
		return Error(self.session, ClientError, "Bad storage command: bad flags")
	} else if exptime, err = strconv.Atoui64(line[3]); err != nil {
		return Error(self.session, ClientError, "Bad storage command: bad expiration time")
	} else if bytes, err = strconv.Atoui64(line[4]); err != nil {
		return Error(self.session, ClientError, "Bad storage command: bad byte-length")
	} else if line[0] == "cas" {
		if casuniq, err = strconv.Atoui64(line[5]); err != nil {
			return Error(self.session, ClientError, "Bad storage command: bad cas value")
		}
	}
	self.command = line[0]
	self.key = line[1]
	self.flags = uint32(flags)
	if exptime == 0 || exptime > secondsInMonth {
		self.exptime = uint32(exptime)
	} else {
		self.exptime = uint32(time.Seconds()) + uint32(exptime)
	}
	self.bytes = uint32(bytes)
	self.cas_unique = casuniq
	if line[len(line)-1] == "noreply" {
		self.noreply = true
	}
	return self.readData()
}
開發者ID:rdarder,項目名稱:gocached,代碼行數:33,代碼來源:command.go

示例2: Incr

func (self *MapCacheStorage) Incr(key string, value uint64, incr bool) (ErrorCode, *StorageEntry, *StorageEntry) {
	self.rwLock.Lock()
	defer self.rwLock.Unlock()
	entry, present := self.storageMap[key]
	if present && !entry.expired() {
		if addValue, err := strconv.Atoui64(string(entry.content)); err == nil {
			var incrValue uint64
			if incr {
				incrValue = uint64(addValue) + value
			} else if value > addValue {
				incrValue = 0
			} else {
				incrValue = uint64(addValue) - value
			}
			incrStrValue := strconv.Uitoa64(incrValue)
			old_value := entry.content
			entry.content = []byte(incrStrValue)
			entry.bytes = uint32(len(entry.content))
			entry.cas_unique += 1
			return Ok, &StorageEntry{entry.exptime, entry.flags, entry.bytes, entry.cas_unique, old_value}, entry
		} else {
			return IllegalParameter, nil, nil
		}
	}
	return KeyNotFound, nil, nil
}
開發者ID:rdarder,項目名稱:gocached,代碼行數:26,代碼來源:mapcachestorage.go

示例3: U64

// Get node value as uint64
func (this *Node) U64(namespace, name string) uint64 {
	if node := rec_SelectNode(this, namespace, name); node != nil && node.Value != "" {
		n, _ := strconv.Atoui64(node.Value)
		return n
	}
	return 0
}
開發者ID:dustywilson,項目名稱:go-pkg-xmlx,代碼行數:8,代碼來源:node.go

示例4: Au64

// Get attribute value as uint64
func (this *Node) Au64(namespace, name string) uint64 {
	if s := this.As(namespace, name); s != "" {
		n, _ := strconv.Atoui64(s)
		return n
	}
	return 0
}
開發者ID:dustywilson,項目名稱:go-pkg-xmlx,代碼行數:8,代碼來源:node.go

示例5: checkForInt

func (r result) checkForInt(c *Conn, s string) (uint64, os.Error) {
	if r.err != nil {
		return 0, Error{c.Name, r.cmd, r.line, r.err}
	}

	if err, ok := replyErrors[r.name]; ok {
		return 0, Error{c.Name, r.cmd, r.line, err}
	}

	if r.name != s {
		return 0, Error{c.Name, r.cmd, r.line, BadReply}
	}

	if len(r.args) != 1 {
		return 0, Error{c.Name, r.cmd, r.line, BadReply}
	}

	n, err := strconv.Atoui64(r.args[0])

	if err != nil {
		return 0, Error{c.Name, r.cmd, r.line, BadReply}
	}

	return n, nil
}
開發者ID:schmichael,項目名稱:beanstalk.go,代碼行數:25,代碼來源:beanstalk.go

示例6: AsUint64

func AsUint64(v interface{}) (uint64, os.Error) {
	switch value := v.(type) {
	default:
		return 0, os.NewError(fmt.Sprintf("unexpected type: %T", value))
	case int:
		return uint64(value), nil
	case int8:
		return uint64(value), nil
	case int16:
		return uint64(value), nil
	case int32:
		return uint64(value), nil
	case int64:
		return uint64(value), nil
	case uint:
		return uint64(value), nil
	case uint8:
		return uint64(value), nil
	case uint16:
		return uint64(value), nil
	case uint32:
		return uint64(value), nil
	case uint64:
		return value, nil
	case float32:
		return uint64(value), nil
	case float64:
		return uint64(value), nil
	case string:
		return strconv.Atoui64(value)
	}
	panic(fmt.Sprintf("unsupported type: %s", reflect.ValueOf(v).Type().Name()))
}
開發者ID:thomaslee,項目名稱:go-ext,代碼行數:33,代碼來源:conversions.go

示例7: checkForJob

func (r result) checkForJob(c *Conn, s string) (*Job, os.Error) {
	if r.err != nil {
		return nil, Error{c.Name, r.cmd, r.line, r.err}
	}

	if err, ok := replyErrors[r.name]; ok {
		return nil, Error{c.Name, r.cmd, r.line, err}
	}

	if r.name != s {
		return nil, Error{c.Name, r.cmd, r.line, BadReply}
	}

	if len(r.args) != 2 {
		return nil, Error{c.Name, r.cmd, r.line, BadReply}
	}

	id, err := strconv.Atoui64(r.args[0])

	if err != nil {
		return nil, Error{c.Name, r.cmd, r.line, BadReply}
	}

	return &Job{id, r.body, c}, nil
}
開發者ID:schmichael,項目名稱:beanstalk.go,代碼行數:25,代碼來源:beanstalk.go

示例8: decodeColumn

func decodeColumn(idx int, field *mysql.Field, val interface{}) (interface{}, os.Error) {
	var dec interface{}
	var err os.Error
	switch v := val.(type) {
	case int64:
		return v, nil
	case []byte:
		switch field.Type {
		case mysql.FIELD_TYPE_TINY, mysql.FIELD_TYPE_SHORT, mysql.FIELD_TYPE_YEAR, mysql.FIELD_TYPE_INT24, mysql.FIELD_TYPE_LONG, mysql.FIELD_TYPE_LONGLONG:
			if field.Flags&mysql.FLAG_UNSIGNED != 0 {
				dec, err = strconv.Atoui64(string(v))
			} else {
				dec, err = strconv.Atoi64(string(v))
			}
			if err != nil {
				return nil, fmt.Errorf("mysql: strconv.Atoi64 error on field %d: %v", idx, err)
			}
		case mysql.FIELD_TYPE_FLOAT, mysql.FIELD_TYPE_DOUBLE:
			dec, err = strconv.Atof64(string(v))
			if err != nil {
				return nil, fmt.Errorf("mysql: strconv.Atof64 error on field %d: %v", idx, err)
			}
		case mysql.FIELD_TYPE_DECIMAL, mysql.FIELD_TYPE_NEWDECIMAL, mysql.FIELD_TYPE_VARCHAR, mysql.FIELD_TYPE_VAR_STRING, mysql.FIELD_TYPE_STRING:
			dec = string(v)
		default:
			return nil, fmt.Errorf("row[%d] was a []byte but unexpected field type %d", idx, field.Type)
		}
		return dec, nil
	}
	return nil, fmt.Errorf("expected row[%d] contents to be a []byte, got %T for field type %d", idx, val, field.Type)
}
開發者ID:ipeet,項目名稱:camlistore,代碼行數:31,代碼來源:mywrap.go

示例9: getIDFromIDFile

func getIDFromIDFile() (uint64, os.Error) {
	G_idServerLock.Lock()
	defer G_idServerLock.Unlock()
	fd, err := os.Open(IDFILE, os.O_RDONLY, 0666)
	if err == nil {
		buf := bufio.NewReader(fd)
		lineofbytes, errb := buf.ReadBytes('\n')
		if errb == nil {
			lineofbytes = TrimCRLF(lineofbytes)
			fd.Close()
			return strconv.Atoui64(string(lineofbytes))
		} else {
			fmt.Println("Error creating bufio.NewReader(fd)")
		}
	} else {
		// Error reading file, does it exist?
		stat, _ := os.Stat(IDFILE)
		if stat == nil {
			// File doesn't exist
			fmt.Println("id.txt doesn't exist... Create one...")
			createNewIDFile()
		} else {
			fmt.Println("Can't open id.txt, but it does exist... FATAL.")
			os.Exit(-2)
		}
		return 0, nil
	}

	return 0, os.NewError("Impossible")
}
開發者ID:GoogleSourceExpoted,項目名稱:goesmtp,代碼行數:30,代碼來源:idserver.go

示例10: U64

func (this ParamList) U64(i int, defval uint64) uint64 {
	if -1 < i && i < len(this) {
		if v, err := strconv.Atoui64(this[i]); err == nil {
			return v
		}
	}
	return defval
}
開發者ID:welterde,項目名稱:mudkip,代碼行數:8,代碼來源:params.go

示例11: U64

func (this *Section) U64(key string, defval uint64) uint64 {
	if v, ok := this.Pairs[key]; ok {
		if n, err := strconv.Atoui64(v); err == nil {
			return n
		}
	}
	return defval
}
開發者ID:welterde,項目名稱:go-pkg-ini,代碼行數:8,代碼來源:section.go

示例12: Euler43

func Euler43() string {
	sum := uint64(0)
	pand := []byte("1023456789")
	for arithmetics.Permute(pand) {
		hasProperty := true
		for i, prime := range smallprimes {
			num, _ := strconv.Atoui64(string(pand[1+i : 4+i]))
			if num%prime != 0 {
				hasProperty = false
				break
			}
		}
		if hasProperty {
			num, _ := strconv.Atoui64(string(pand))
			sum += num
		}
	}
	return fmt.Sprint(sum)
}
開發者ID:Narsil,項目名稱:go-euler,代碼行數:19,代碼來源:problem43.go

示例13: prepare

func (self *Coder) prepare() {
	if self.Ctx == nil {
		self.Ctx = C.avcodec_alloc_context()
		cid, _ := strconv.Atoui64(self.Parameter["codecid"])
		self.Ctx.codec_id = uint32(cid)
	}
	/**
	 * @TODO: settng the fixed params like width, height, channels...
	 */
}
開發者ID:psychobob666,項目名稱:MediaEncodingCluster,代碼行數:10,代碼來源:ffmpeg.go

示例14: update

func (cl *cleaner) update(ev store.Event) {
	parts := strings.Split(ev.Path, "/", -1)
	id := parts[3]
	seqn, err := strconv.Atoui64(ev.Body)
	if err != nil {
		cl.logger.Println(err)
		return
	}
	cl.table[id] = seqn
}
開發者ID:andradeandrey,項目名稱:doozer,代碼行數:10,代碼來源:clean.go

示例15: copyValue

func copyValue(dst reflect.Value, src []byte) (err os.Error) {
	// Helper functions for integer and unsigned integer conversions
	var itmp int64
	getInt64 := func() bool {
		itmp, err = strconv.Atoi64(string(src))
		// TODO: should check sizes
		return err == nil
	}
	var utmp uint64
	getUint64 := func() bool {
		utmp, err = strconv.Atoui64(string(src))
		// TODO: check for overflow?
		return err == nil
	}
	var ftmp float64
	getFloat64 := func() bool {
		ftmp, err = strconv.Atof64(string(src))
		// TODO: check for overflow?
		return err == nil
	}

	// Save accumulated data and comments
	switch t := dst; t.Kind() {
	case reflect.Invalid:
		// Probably a comment, handled below
	default:
		return os.NewError("cannot happen: unknown type " + t.Type().String())
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		if !getInt64() {
			return err
		}
		t.SetInt(itmp)
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
		if !getUint64() {
			return err
		}
		t.SetUint(utmp)
	case reflect.Float32, reflect.Float64:
		if !getFloat64() {
			return err
		}
		t.SetFloat(ftmp)
	case reflect.Bool:
		value, err := strconv.Atob(strings.TrimSpace(string(src)))
		if err != nil {
			return err
		}
		t.SetBool(value)
	case reflect.String:
		t.SetString(string(src))
	case reflect.Slice:
		t.Set(reflect.ValueOf(src))
	}
	return nil
}
開發者ID:Quantumboost,項目名稱:gcc,代碼行數:55,代碼來源:read.go


注:本文中的strconv.Atoui64函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。