Clash.Meta/common/utils/uuid.go

24 lines
535 B
Go
Raw Normal View History

package utils
import (
"github.com/gofrs/uuid"
2023-03-05 11:00:14 +08:00
"github.com/zhangyunhao116/fastrand"
)
2023-03-05 11:00:14 +08:00
type fastRandReader struct{}
func (r fastRandReader) Read(p []byte) (int, error) {
return fastrand.Read(p)
}
var UnsafeUUIDGenerator = uuid.NewGenWithOptions(uuid.WithRandomReader(fastRandReader{}))
2022-05-07 12:35:14 +08:00
// UUIDMap https://github.com/XTLS/Xray-core/issues/158#issue-783294090
func UUIDMap(str string) (uuid.UUID, error) {
u, err := uuid.FromString(str)
if err != nil {
2023-03-05 11:00:14 +08:00
return UnsafeUUIDGenerator.NewV5(uuid.Nil, str), nil
}
return u, nil
}