gpt4 book ai didi

python - Golang 中 UUID4 的整数表示

转载 作者:IT王子 更新时间:2023-10-29 01:25:30 27 4
gpt4 key购买 nike

我正在尝试在 Golang 中解析 UUID4,但我需要一些特定信息:整数表示。

在 python 中我使用:

uuid.uuid4().int 

但在 Golang 中它不存在(或者在我用谷歌搜索的任何其他 uuid 库中)。

有没有办法将一个简单的 UUID 解析成它的整数表示形式?

最佳答案

假设你的 uuid 类型是一个字符串:

func main() {
uuid := `25f64dba-634d-4613-9516-9ca61b161454`
var i big.Int
i.SetString(strings.Replace(uuid, "-", "", 4), 16)
//or if your uuid is [16]byte
//i.SetBytes(uuid[:])
fmt.Println(i.String())
}

playground

关于python - Golang 中 UUID4 的整数表示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24871177/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com