问题描述
我的当前Python代码是:
uuid.uuid1()。hex [:16] //我需要16个字符文件名
golang相当于什么?
谢谢!
在Go的标准库中没有guid或uuid类型,但还有其他一些方法可以实现它,例如使用像这样的第三方包; https://godoc.org/code.google.com/p/ go-uuid / uuid 或 https://github.com/nu7hatch/guuid
导入github.com/nu7hatch/gouuid
id,err:= uuid.NewV4( )
这个答案还有另一个选项,它使用Unix命令行utils; 是否有一种方法可以生成一个UUID语言,尽管它似乎表现不佳。
I need to generate an unique file name with UUID1.
My current python code is:
uuid.uuid1().hex[:16] // i need 16 chars file name
What could be the golang equivalent?
Thanks!
There isn't a guid or uuid type in the standard library for Go but there are some other ways to do it, like using a third party package such as this; https://godoc.org/code.google.com/p/go-uuid/uuid or https://github.com/nu7hatch/gouuid
import "github.com/nu7hatch/gouuid"
id, err := uuid.NewV4()
This answer has another option as well which makes use of Unix command line utils; Is there a method to generate a UUID with go language though it doesn't seem to perform very well.
这篇关于在golang中使用UUID生成唯一的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!