2 回答
TA贡献1887条经验 获得超5个赞
您可以使用该Bytes()函数获取字节,然后使用encoding/binary. 正如@icza 所提到的,您也可以直接对 UUID 对象进行切片,因此您甚至不需要调用Bytes().
package main
import "fmt"
import "encoding/binary"
import "github.com/satori/go.uuid"
func main() {
u1 := uuid.NewV4()
fmt.Printf("UUIDv4: %s\n", u1)
l1 := binary.BigEndian.Uint64(u1[:8])
l2 := binary.BigEndian.Uint64(u1[8:])
fmt.Printf("%x %x\n", l1, l2)
fmt.Printf("%v %v\n", l1, l2)
}
TA贡献1839条经验 获得超15个赞
例如,
package main
import (
"encoding/binary"
"fmt"
"github.com/satori/go.uuid"
)
func main() {
u := uuid.NewV4()
fmt.Printf("%s\n", u)
u1 := binary.BigEndian.Uint64(u[0:8])
u2 := binary.BigEndian.Uint64(u[8:16])
fmt.Printf("%x %x\n", u1, u2)
}
输出:
eb33dcfa-e439-4ff9-b366-bcd397e0852f
eb33dcfae4394ff9 b366bcd397e0852f
- 2 回答
- 0 关注
- 231 浏览
添加回答
举报