本文整理汇总了Golang中strconv.Uitoa函数的典型用法代码示例。如果您正苦于以下问题:Golang Uitoa函数的具体用法?Golang Uitoa怎么用?Golang Uitoa使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Uitoa函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AsString
func AsString(v interface{}) (string, os.Error) {
switch value := v.(type) {
default:
return "", os.NewError(fmt.Sprintf("unexpected type: %T", value))
case int:
return strconv.Itoa(value), nil
case int8:
return strconv.Itoa(int(value)), nil
case int16:
return strconv.Itoa(int(value)), nil
case int32:
return strconv.Itoa(int(value)), nil
case int64:
return strconv.Itoa64(value), nil
case uint:
return strconv.Uitoa(value), nil
case uint8:
return strconv.Uitoa(uint(value)), nil
case uint16:
return strconv.Uitoa(uint(value)), nil
case uint32:
return strconv.Uitoa(uint(value)), nil
case uint64:
return strconv.Uitoa64(value), nil
case float32:
return strconv.Ftoa32(value, 'g', -1), nil
case float64:
return strconv.Ftoa64(value, 'g', -1), nil
case string:
return value, nil
}
panic(fmt.Sprintf("unsupported type: %s", reflect.ValueOf(v).Type().Name()))
}
示例2: valueToString
func valueToString(v reflect.Value) (string, os.Error) {
if v == nil {
return "null", nil
}
switch v := v.(type) {
case *reflect.PtrValue:
return valueToString(reflect.Indirect(v))
case *reflect.InterfaceValue:
return valueToString(v.Elem())
case *reflect.BoolValue:
x := v.Get()
if x {
return "true", nil
} else {
return "false", nil
}
case *reflect.IntValue:
return strconv.Itoa(v.Get()), nil
case *reflect.Int8Value:
return strconv.Itoa(int(v.Get())), nil
case *reflect.Int16Value:
return strconv.Itoa(int(v.Get())), nil
case *reflect.Int32Value:
return strconv.Itoa(int(v.Get())), nil
case *reflect.Int64Value:
return strconv.Itoa64(v.Get()), nil
case *reflect.UintValue:
return strconv.Uitoa(v.Get()), nil
case *reflect.Uint8Value:
return strconv.Uitoa(uint(v.Get())), nil
case *reflect.Uint16Value:
return strconv.Uitoa(uint(v.Get())), nil
case *reflect.Uint32Value:
return strconv.Uitoa(uint(v.Get())), nil
case *reflect.Uint64Value:
return strconv.Uitoa64(v.Get()), nil
case *reflect.UintptrValue:
return strconv.Uitoa64(uint64(v.Get())), nil
case *reflect.FloatValue:
return strconv.Ftoa(v.Get(), 'g', -1), nil
case *reflect.Float32Value:
return strconv.Ftoa32(v.Get(), 'g', -1), nil
case *reflect.Float64Value:
return strconv.Ftoa64(v.Get(), 'g', -1), nil
case *reflect.StringValue:
return v.Get(), nil
case *reflect.SliceValue:
typ := v.Type().(*reflect.SliceType)
if _, ok := typ.Elem().(*reflect.Uint8Type); ok {
return string(v.Interface().([]byte)), nil
}
}
return "", os.NewError("Unsupported type")
}
示例3: cdmValuesCell
func cdmValuesCell(min uint, max uint) string {
if min == max {
return "<td>" + strconv.Uitoa(min) + "</td>"
}
if max == 0 {
return "<td>" + strconv.Uitoa(min) + " - +∞</td>"
}
return "<td>" + strconv.Uitoa(min) + " - " + strconv.Uitoa(max) + "</td>"
}
示例4: String
func (g Grid) String() string {
rowStrings := make([]string, g.Height+1)
rowStrings[0] = strings.Join([]string{strconv.Uitoa(g.Width), strconv.Uitoa(g.Height)}, " ")
for y := uint(0); y < g.Height; y++ {
row := make([]string, g.Width)
for x := uint(0); x < g.Width; x++ {
row[x] = strconv.Uitoa(uint(g.Get(x, y)))
}
rowStrings[y+1] = strings.Join(row, " ")
}
return strings.Join(rowStrings, "\n")
}
示例5: Print
func (char *CdmChar) Print(name string) {
fmt.Println(" " + name + " :")
fmt.Println(" text : \"" + char.Text + "\"")
if char.Min != 0 {
fmt.Println(" min : " + strconv.Uitoa(char.Min))
}
if char.Max != 0 {
fmt.Println(" max : " + strconv.Uitoa(char.Max))
}
if char.Value != 0 {
fmt.Println(" value : " + strconv.Uitoa(char.Value))
}
}
示例6: CountColor
func CountColor(png io.Reader) int {
var pic image.Image
var color image.Color
pic, e := p.Decode(png)
if e != nil {
fmt.Printf("Error %v\n", e)
return 0
}
cnt := 0
colormap := make(map[string]int)
for y := 0; y < pic.Bounds().Size().Y; y++ {
for x := 0; x < pic.Bounds().Size().X; x++ {
color = pic.At(x, y)
r, g, b, _ := color.RGBA()
key := ""
if uint8(r) < 10 {
key += "00" + strconv.Uitoa(uint(uint8(r)))
} else if uint8(r) < 100 {
key += "0" + strconv.Uitoa(uint(uint8(r)))
} else {
key += strconv.Uitoa(uint(uint8(r)))
}
if uint8(g) < 10 {
key += "00" + strconv.Uitoa(uint(uint8(g)))
} else if uint8(g) < 100 {
key += "0" + strconv.Uitoa(uint(uint8(g)))
} else {
key += strconv.Uitoa(uint(uint8(g)))
}
if uint8(b) < 10 {
key += "00" + strconv.Uitoa(uint(uint8(b)))
} else if uint8(b) < 100 {
key += "0" + strconv.Uitoa(uint(uint8(b)))
} else {
key += strconv.Uitoa(uint(uint8(b)))
}
if val, exist := colormap[key]; exist {
colormap[key] = val + 1
} else {
colormap[key] = 1
cnt++
}
}
}
return cnt
}
示例7: addUintsNV
func addUintsNV(c []NameValue, label string, min uint, max uint) []NameValue {
if min == 0 && max == 0 {
return c
}
n := len(c)
c = c[0 : n+1]
if max == 0 {
c[n] = NameValue{label, strconv.Uitoa(min) + " - ?"}
} else if min == max {
c[n] = NameValue{label, strconv.Uitoa(min)}
} else {
c[n] = NameValue{label, strconv.Uitoa(min) + " - " + strconv.Uitoa(max)}
}
return c
}
示例8: String
func (p *Place) String() string {
str := strconv.Uitoa(p.Id) + ") " + p.Name + " nominated by " + p.Nominator.Name + " [" + strconv.Uitoa(p.Votes) + " votes]"
for _, person := range p.People {
str += "\n - " + person.String()
}
return str
}
示例9: Prepare
/**
* Prepare sql statement
*/
func (stmt *MySQLStatement) Prepare(sql string) (err os.Error) {
mysql := stmt.mysql
if mysql.Logging {
log.Print("Prepare statement called")
}
// Lock mutex and defer unlock
mysql.mutex.Lock()
defer mysql.mutex.Unlock()
// Reset error/sequence vars
mysql.reset()
stmt.reset()
// Send command
err = stmt.command(COM_STMT_PREPARE, sql)
if err != nil {
return
}
if mysql.Logging {
log.Print("[" + strconv.Uitoa(uint(mysql.sequence-1)) + "] Sent prepare command to server")
}
// Get result packet(s)
for {
// Get result packet
err = stmt.getPrepareResult()
if err != nil {
return
}
// Break when end of field packets reached
if stmt.result.fieldsEOF {
break
}
}
stmt.prepared = true
return
}
示例10: GetBlessure
// un résultat sans auteur (0) ni dateCdm (valeur 0) signifie qu'on n'a pas la réponse à la question
func (store *MysqlStore) GetBlessure(db *mysql.Client, numMonstre uint, trollId int, amis []int) (blessure uint, auteurCDM int, dateCDM int64, err os.Error) {
sql := "select blessure, author, date_adition from cdm where"
sql += " num_monstre=" + strconv.Uitoa(numMonstre) + " and"
sql += " author in (" + strconv.Itoa(trollId)
for _, id := range amis {
sql += "," + strconv.Itoa(id)
}
sql += ") order by date_adition desc limit 1"
err = db.Query(sql)
if err != nil {
return
}
result, err := db.UseResult()
if err != nil {
return
}
row := result.FetchRow()
db.FreeResult()
if row == nil {
return
}
blessure = fieldAsUint(row[0])
auteurCDM = fieldAsInt(row[1])
dateCDM = fieldAsInt64(row[2])
return
}
示例11: Reset
/**
* Reset statement
*/
func (stmt *MySQLStatement) Reset() (err os.Error) {
mysql := stmt.mysql
if mysql.Logging {
log.Print("Reset statement called")
}
// Lock mutex and defer unlock
mysql.mutex.Lock()
defer mysql.mutex.Unlock()
// Check statement has been prepared
if !stmt.prepared {
stmt.error(CR_NO_PREPARE_STMT, CR_NO_PREPARE_STMT_STR)
err = os.NewError("Statement must be prepared to use this function")
return
}
// Reset error/sequence vars
mysql.reset()
stmt.reset()
// Send command
err = stmt.command(COM_STMT_RESET, stmt.StatementId)
if err != nil {
return
}
if mysql.Logging {
log.Print("[" + strconv.Uitoa(uint(mysql.sequence-1)) + "] Sent reset statement command to server")
}
err = stmt.getResetResult()
if err != nil {
return
}
stmt.paramsRebound = true
return
}
示例12: SendLongData
/**
* Send long data packet
*/
func (stmt *MySQLStatement) SendLongData(num uint16, data string) (err os.Error) {
mysql := stmt.mysql
if mysql.Logging {
log.Print("Send long data called")
}
// Check statement has been prepared
if !stmt.prepared {
stmt.error(CR_NO_PREPARE_STMT, CR_NO_PREPARE_STMT_STR)
err = os.NewError("Statement must be prepared to use this function")
return
}
// Lock mutex and defer unlock
mysql.mutex.Lock()
defer mysql.mutex.Unlock()
// Reset error/sequence vars
mysql.reset()
stmt.reset()
// Construct packet
pkt := new(packetLongData)
pkt.sequence = mysql.sequence
pkt.command = COM_STMT_SEND_LONG_DATA
pkt.statementId = stmt.StatementId
pkt.paramNumber = num
pkt.data = data
err = pkt.write(mysql.writer)
if err != nil {
stmt.error(CR_MALFORMED_PACKET, CR_MALFORMED_PACKET_STR)
return
}
mysql.sequence++
if mysql.Logging {
log.Print("[" + strconv.Uitoa(uint(mysql.sequence-1)) + "] " + "Sent long data packet to server")
}
return
}
示例13: GetCompte
// lit un compte en base. Renvoie nil si le compte n'existe pas en base.
// Sinon l'appelant est responsable de l'ouverture et de la fermeture de la connexion qu'il fournit
func (store *MysqlStore) GetCompte(db *mysql.Client, trollId uint) (c *Compte, err os.Error) {
if trollId == 0 {
fmt.Println("GetCompte> trollId invalide")
return
}
sql := "select statut, mdp_restreint, pv_max, pv_actuels, x, y, z, fatigue, pa, vue, prochain_tour, duree_tour, mise_a_jour"
sql += " from compte where id=" + strconv.Uitoa(trollId)
err = db.Query(sql)
if err != nil {
return
}
result, err := db.UseResult()
if err != nil {
return
}
defer result.Free()
row := result.FetchRow()
if row == nil {
return
}
c = rowToCompte(trollId, row)
return
}
示例14: readResponse
// returns length of response & payload & err
func (b *Broker) readResponse(conn *net.TCPConn) (uint32, []byte, os.Error) {
reader := bufio.NewReader(conn)
length := make([]byte, 4)
lenRead, err := io.ReadFull(reader, length)
if err != nil {
return 0, []byte{}, err
}
if lenRead != 4 || lenRead < 0 {
return 0, []byte{}, os.NewError("invalid length of the packet length field")
}
expectedLength := binary.BigEndian.Uint32(length)
messages := make([]byte, expectedLength)
lenRead, err = io.ReadFull(reader, messages)
if err != nil {
return 0, []byte{}, err
}
if uint32(lenRead) != expectedLength {
return 0, []byte{}, os.NewError(fmt.Sprintf("Fatal Error: Unexpected Length: %d expected: %d", lenRead, expectedLength))
}
errorCode := binary.BigEndian.Uint16(messages[0:2])
if errorCode != 0 {
return 0, []byte{}, os.NewError(strconv.Uitoa(uint(errorCode)))
}
return expectedLength, messages[2:], nil
}
示例15: RunWebServer
func RunWebServer(line *util.ChannelLine) {
util.WebOut = line
web.SetLogger(log.New(new(dummy), "", 0))
web.Config.CookieSecret = util.Settings.CookieSecret()
web.Get("/Liberator/(.*)", get)
web.Get("/(.*)", index)
web.Post("/Liberator/(.*)", post)
web.Run("0.0.0.0:" + strconv.Uitoa(util.Settings.WebPort()))
}