首页  

go google uuid 例子     所属分类 go 浏览量 475
package main

import (
    "fmt"
    "github.com/google/uuid"
)

func main(){
  uuid1, _ := uuid.NewUUID()
  uuid1str := uuid1.String()
  fmt.Println(uuid1str)
  

  bytes := uuid1[:]
  fmt.Println(bytes)
  // 16
  fmt.Println(len(bytes))
  
  
  uuid2,_ := uuid.Parse(uuid1str)
  uuid2str := uuid2.String()
  fmt.Println(uuid2str)
  
  
  uuid3,_ := uuid.ParseBytes(bytes)
  uuid3str := uuid3.String()
  // 00000000-0000-0000-0000-000000000000
  // 注意要用 FromBytes
  fmt.Println(uuid3str)
  
  uuid4,_ := uuid.FromBytes(bytes)
  uuid4str := uuid4.String()
  fmt.Println(uuid4str)
 
}


输出 abdeb3da-c16e-11ec-a8c6-acbc328bd447 [171 222 179 218 193 110 17 236 168 198 172 188 50 139 212 71] 16 abdeb3da-c16e-11ec-a8c6-acbc328bd447 00000000-0000-0000-0000-000000000000 abdeb3da-c16e-11ec-a8c6-acbc328bd447
https://gitee.com/dyyx/hellocode/blob/master/demo/go/gocode/uuidtest.go

上一篇     下一篇
temporal 代码阅读记录

temporal namespace 信息获取 关键代码及堆栈信息

go.sum 生成

java hex util

c语言获取UUID

UUID简介