trim uuid
This commit is contained in:
Родитель
1c6a1aad33
Коммит
93b4cf7945
51
uuid/uuid.go
51
uuid/uuid.go
|
@ -1,27 +1,5 @@
|
|||
package uuid
|
||||
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
|
@ -39,10 +17,14 @@ const (
|
|||
V4
|
||||
_
|
||||
|
||||
VariantNCS byte = iota
|
||||
_ byte = iota
|
||||
VariantRFC4122
|
||||
VariantMicrosoft
|
||||
VariantFuture
|
||||
)
|
||||
|
||||
type (
|
||||
// UUID representation compliant with specification
|
||||
// described in RFC 4122.
|
||||
UUID [Size]byte
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -53,12 +35,6 @@ var (
|
|||
Nil = UUID{}
|
||||
)
|
||||
|
||||
type (
|
||||
// UUID representation compliant with specification
|
||||
// described in RFC 4122.
|
||||
UUID [Size]byte
|
||||
)
|
||||
|
||||
// NewV4 returns random generated UUID.
|
||||
func NewV4() (UUID, error) {
|
||||
u := UUID{}
|
||||
|
@ -76,18 +52,7 @@ func (u *UUID) setVersion(v byte) {
|
|||
}
|
||||
|
||||
func (u *UUID) setVariant(v byte) {
|
||||
switch v {
|
||||
case VariantNCS:
|
||||
u[8] = u[8]&(0xff>>1) | (0x00 << 7)
|
||||
case VariantRFC4122:
|
||||
u[8] = u[8]&(0xff>>2) | (0x02 << 6)
|
||||
case VariantMicrosoft:
|
||||
u[8] = u[8]&(0xff>>3) | (0x06 << 5)
|
||||
case VariantFuture:
|
||||
fallthrough
|
||||
default:
|
||||
u[8] = u[8]&(0xff>>3) | (0x07 << 5)
|
||||
}
|
||||
u[8] = u[8]&(0xff>>2) | (0x02 << 6)
|
||||
}
|
||||
|
||||
func (u UUID) String() string {
|
||||
|
|
Загрузка…
Ссылка в новой задаче