标签:nbsp 数据类型 oat bytes lang test eset 种类型 ret
golang中的string是可以转换为byte数组或者rune数组
但是其实byte对应的类型是uint8,而rune对应的数据类型就是int32
所以string可以转换为四种类型
//interface转其他类型————返回值是interface,直接赋值是无法转化的
//interface 转string
var a interface{}
var str5 string
a = "3432423"
str5 = a.(string)
fmt.Println(str5)
//interface 转int
var m interface{}
var m1 int
m = 43
m1 = m.(int)
fmt.Println(m1)
//interface 转float64
var ff interface{}
var ff1 float64
ff = 432.54
ff1 = ff.(float64)
fmt.Println(ff1)
原文链接:https://blog.csdn.net/a1053904672/java/article/details/90277282
package main
import (
"bytes"
"io"
"os"
"sync"
"time"
)
var bufPool = sync.Pool {
New: func() interface{} {
return new(bytes.Buffer)
},
}
func PoolTest(w io.Writer, key, val string) {
b, _ := bufPool.Get().(*bytes.Buffer) //interface转(*bytes.Buffer)
b.Reset()
b.WriteString(time.Now().UTC().Format("2006-01-02 15:04:05"))
b.WriteByte(‘|‘)
b.WriteString(key)
b.WriteByte(‘=‘)
b.WriteString(val)
w.Write(b.Bytes())
w.Write([]byte("\n"))
bufPool.Put(b)
}
func main() {
PoolTest(os.Stdout, "dablelv", "monkey")
}
原文链接:https://blog.csdn.net/k346k346/java/article/details/95660971
标签:nbsp 数据类型 oat bytes lang test eset 种类型 ret
原文地址:https://www.cnblogs.com/longchang/p/12613303.html