func FromString(s string) (u UUID, e error) {
	if len(s) != UUIDStringLen {
		return nil, &BadUUIDStringError{"length is not 36 bytes: " + s}
	}
	u = make([]byte, UUIDByteLen)
	s_byte := []byte(s)
	var i int
	var err error
	i, err = hex.Decode(u[0:4], s_byte[0:8])
	if err != nil || i != 4 {
		return nil, &BadUUIDStringError{"Invalid first component: " + s}
	}
	if s_byte[8] != '-' {
		return nil, &BadUUIDStringError{"Position 8 is not a dash: " + s}
	}
	i, err = hex.Decode(u[4:6], s_byte[9:13])
	if err != nil || i != 2 {
		return nil, &BadUUIDStringError{"Invalid second component: " + s}
	}
	if s_byte[13] != '-' {
		return nil, &BadUUIDStringError{"Position 13 is not a dash: " + s}
	}
	i, err = hex.Decode(u[6:8], s_byte[14:18])
	if err != nil || i != 2 {
		return nil, &BadUUIDStringError{"Invalid third component: " + s}
	}
	if s_byte[18] != '-' {
		return nil, &BadUUIDStringError{"Position 18 is not a dash: " + s}
	}
	i, err = hex.Decode(u[8:10], s_byte[19:23])
	if err != nil || i != 2 {
		return nil, &BadUUIDStringError{"Invalid fourth component: " + s}
	}
	if s_byte[23] != '-' {
		return nil, &BadUUIDStringError{"Position 23 is not a dash: " + s}
	}
	i, err = hex.Decode(u[10:16], s_byte[24:36])
	if err != nil || i != 6 {
		return nil, &BadUUIDStringError{"Invalid fifth component: " + s}
	}
	if u[8]&0xc0 != 0x80 {
		return nil, &BadUUIDStringError{"Reserved bits used: " + s}
	}
	return u, nil
}
Converts a string representation of a UUID into a UUID object.
package uuid
import (
	"bytes"
	"crypto/md5"
	crypto_rand "crypto/rand"
	"crypto/sha1"
	"encoding/hex"
	"fmt"
	"io"
	math_rand "math/rand"
	"net"
	"sync"
	"time"
)
const Variant1EpochOffset = 12219292800000
const UUIDByteLen = 16
const UUIDStringLen = 36
const UUIDHardwareByteLen = 6
type UUID []byte
type UUIDSlice []byte
func (u UUIDSlice) Len() int {
	return len(u)
}
func (u UUIDSlice) Less(i, j int) bool {
	return u[i] < u[j]
}
func (u UUIDSlice) Swap(i, j int) {
	u[i], u[j] = u[j], u[i]
}
var setupOnce sync.Once
var nodeName []byte
var lastTime int64
var clockCorrect uint16
func setNodeName() {
	clockCorrect = uint16(math_rand.Int31() & 0xffff)
	interfaces, _ := net.Interfaces()
	if interfaces != nil {
		for _, i := range interfaces {
			if len(i.HardwareAddr) == UUIDHardwareByteLen {
				nodeName = i.HardwareAddr
				return
			}
		}
	}
	nodeName = make([]byte, UUIDHardwareByteLen)
	io.ReadFull(crypto_rand.Reader, nodeName)
	nodeName[0] = nodeName[0] | 0x01
}
func Variant1() (u UUID) {
	setupOnce.Do(setNodeName)
	ts := (time.Now().UnixNano() / 100) + Variant1EpochOffset
	if ts == lastTime {
		clockCorrect += 1
	} else {
		lastTime = ts
	}
	u = make([]byte, UUIDByteLen)
	u[0] = byte((ts >> (3 * 8)) & 0xff)
	u[1] = byte((ts >> (2 * 8)) & 0xff)
	u[2] = byte((ts >> (1 * 8)) & 0xff)
	u[3] = byte(ts & 0xff)
	u[4] = byte((ts >> (5 * 8)) & 0xff)
	u[5] = byte((ts >> (4 * 8)) & 0xff)
	u[6] = byte((ts>>(7*8))&0x0f + 0x10)
	u[7] = byte((ts >> (6 * 8)) & 0xff)
	u[8] = byte((clockCorrect>>1)&0x1f) | 0x80
	u[9] = byte(clockCorrect & 0xff)
	u[10] = byte(nodeName[0])
	u[11] = byte(nodeName[1])
	u[12] = byte(nodeName[2])
	u[13] = byte(nodeName[3])
	u[14] = byte(nodeName[4])
	u[15] = byte(nodeName[5])
	return u
}
func NameSpaceDNS() UUID {
	return UUID{107, 167, 184, 16, 157, 173, 17, 209,
		128, 180, 0, 192, 79, 212, 48, 200}
}
func NameSpaceURL() UUID {
	return UUID{107, 167, 184, 17, 157, 173, 17, 209,
		128, 180, 0, 192, 79, 212, 48, 200}
}
func NameSpaceOID() UUID {
	return UUID{107, 167, 184, 18, 157, 173, 17, 209,
		128, 180, 0, 192, 79, 212, 48, 200}
}
func NameSpaceX500() UUID {
	return UUID{107, 167, 184, 18, 157, 173, 17, 209,
		128, 180, 0, 192, 79, 212, 48, 200}
}
func Variant3(namespace UUID, name string) (u UUID) {
	h := md5.New()
	h.Write([]byte(namespace))
	h.Write([]byte(name))
	u = h.Sum(nil)[0:16]
	u[6] = (u[6] & 0x0f) | 0x30
	u[8] = (u[8] & 0x1f) | 0x80
	return u
}
func Variant4() (u UUID) {
	u = make([]byte, UUIDByteLen)
	io.ReadFull(crypto_rand.Reader, u)
	u[6] = (u[6] & 0x0f) + 0x40
	u[8] = (u[8] & 0x1f) + 0x80
	return u
}
func Variant5(namespace UUID, name string) (u UUID) {
	h := sha1.New()
	h.Write([]byte(namespace))
	h.Write([]byte(name))
	u = h.Sum(nil)[0:16]
	u[6] = (u[6] & 0x0f) | 0x50
	u[8] = (u[8] & 0x3f) | 0x80
	return u
}
func Generate() UUID {
	return Variant1()
}
func (u UUID) Compare(o UUID) int {
	return bytes.Compare(u, o)
}
func (u UUID) Equal(o UUID) bool {
	return bytes.Equal(u, o)
}
var hexBytes = [...]byte{
	'0', '1', '2', '3', '4', '5', '6', '7',
	'8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
}
func (u UUID) String() string {
	output := make([]byte, UUIDStringLen)
	output[0] = hexBytes[(u[0]&0xf0)>>4]
	output[1] = hexBytes[(u[0] & 0x0f)]
	output[2] = hexBytes[(u[1]&0xf0)>>4]
	output[3] = hexBytes[(u[1] & 0x0f)]
	output[4] = hexBytes[(u[2]&0xf0)>>4]
	output[5] = hexBytes[(u[2] & 0x0f)]
	output[6] = hexBytes[(u[3]&0xf0)>>4]
	output[7] = hexBytes[(u[3] & 0x0f)]
	output[8] = '-'
	output[9] = hexBytes[(u[4]&0xf0)>>4]
	output[10] = hexBytes[(u[4] & 0x0f)]
	output[11] = hexBytes[(u[5]&0xf0)>>4]
	output[12] = hexBytes[(u[5] & 0x0f)]
	output[13] = '-'
	output[14] = hexBytes[(u[6]&0xf0)>>4]
	output[15] = hexBytes[(u[6] & 0x0f)]
	output[16] = hexBytes[(u[7]&0xf0)>>4]
	output[17] = hexBytes[(u[7] & 0x0f)]
	output[18] = '-'
	output[19] = hexBytes[(u[8]&0xf0)>>4]
	output[20] = hexBytes[(u[8] & 0x0f)]
	output[21] = hexBytes[(u[9]&0xf0)>>4]
	output[22] = hexBytes[(u[9] & 0x0f)]
	output[23] = '-'
	output[24] = hexBytes[(u[10]&0xf0)>>4]
	output[25] = hexBytes[(u[10] & 0x0f)]
	output[26] = hexBytes[(u[11]&0xf0)>>4]
	output[27] = hexBytes[(u[11] & 0x0f)]
	output[28] = hexBytes[(u[12]&0xf0)>>4]
	output[29] = hexBytes[(u[12] & 0x0f)]
	output[30] = hexBytes[(u[13]&0xf0)>>4]
	output[31] = hexBytes[(u[13] & 0x0f)]
	output[32] = hexBytes[(u[14]&0xf0)>>4]
	output[33] = hexBytes[(u[14] & 0x0f)]
	output[34] = hexBytes[(u[15]&0xf0)>>4]
	output[35] = hexBytes[(u[15] & 0x0f)]
	return string(output)
}
func (u UUID) MarshalJSON() ([]byte, error) {
	return []byte(fmt.Sprintf("\"%s\"", u.String())), nil
}
func (u UUID) Bytes() []byte {
	return u
}
type BadUUIDStringError struct {
	message string
}
func (e *BadUUIDStringError) Error() string {
	return e.message
}