daShangDao_planA/planB/tool/uuid.go

20 lines
496 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package tool
import (
"fmt"
"github.com/google/uuid"
)
// GenerateUUID 生成一个版本4随机的UUID字符串
// 返回值uuid字符串错误信息如果生成失败
func GenerateUUID() (string, error) {
// NewUUID 生成版本4的随机UUID最常用的类型
uuidObj, err := uuid.NewRandom()
if err != nil {
return "", fmt.Errorf("生成UUID失败: %v", err)
}
// 将UUID对象转为字符串标准格式8-4-4-4-12
return uuidObj.String(), nil
}