在golang中使用UUID生成唯一的文件名 [英] Generating unique file name using UUID in golang

查看:1218
本文介绍了在golang中使用UUID生成唯一的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的当前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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆