aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/satori/go.uuid
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/satori/go.uuid')
-rw-r--r--vendor/github.com/satori/go.uuid/.travis.yml23
-rw-r--r--vendor/github.com/satori/go.uuid/LICENSE20
-rw-r--r--vendor/github.com/satori/go.uuid/README.md65
-rw-r--r--vendor/github.com/satori/go.uuid/codec.go206
-rw-r--r--vendor/github.com/satori/go.uuid/generator.go239
-rw-r--r--vendor/github.com/satori/go.uuid/sql.go78
-rw-r--r--vendor/github.com/satori/go.uuid/uuid.go161
7 files changed, 792 insertions, 0 deletions
diff --git a/vendor/github.com/satori/go.uuid/.travis.yml b/vendor/github.com/satori/go.uuid/.travis.yml
new file mode 100644
index 0000000..20dd53b
--- /dev/null
+++ b/vendor/github.com/satori/go.uuid/.travis.yml
@@ -0,0 +1,23 @@
1language: go
2sudo: false
3go:
4 - 1.2
5 - 1.3
6 - 1.4
7 - 1.5
8 - 1.6
9 - 1.7
10 - 1.8
11 - 1.9
12 - tip
13matrix:
14 allow_failures:
15 - go: tip
16 fast_finish: true
17before_install:
18 - go get github.com/mattn/goveralls
19 - go get golang.org/x/tools/cmd/cover
20script:
21 - $HOME/gopath/bin/goveralls -service=travis-ci
22notifications:
23 email: false
diff --git a/vendor/github.com/satori/go.uuid/LICENSE b/vendor/github.com/satori/go.uuid/LICENSE
new file mode 100644
index 0000000..926d549
--- /dev/null
+++ b/vendor/github.com/satori/go.uuid/LICENSE
@@ -0,0 +1,20 @@
1Copyright (C) 2013-2018 by Maxim Bublis <b@codemonkey.ru>
2
3Permission is hereby granted, free of charge, to any person obtaining
4a copy of this software and associated documentation files (the
5"Software"), to deal in the Software without restriction, including
6without limitation the rights to use, copy, modify, merge, publish,
7distribute, sublicense, and/or sell copies of the Software, and to
8permit persons to whom the Software is furnished to do so, subject to
9the following conditions:
10
11The above copyright notice and this permission notice shall be
12included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/vendor/github.com/satori/go.uuid/README.md b/vendor/github.com/satori/go.uuid/README.md
new file mode 100644
index 0000000..7b1a722
--- /dev/null
+++ b/vendor/github.com/satori/go.uuid/README.md
@@ -0,0 +1,65 @@
1# UUID package for Go language
2
3[![Build Status](https://travis-ci.org/satori/go.uuid.png?branch=master)](https://travis-ci.org/satori/go.uuid)
4[![Coverage Status](https://coveralls.io/repos/github/satori/go.uuid/badge.svg?branch=master)](https://coveralls.io/github/satori/go.uuid)
5[![GoDoc](http://godoc.org/github.com/satori/go.uuid?status.png)](http://godoc.org/github.com/satori/go.uuid)
6
7This package provides pure Go implementation of Universally Unique Identifier (UUID). Supported both creation and parsing of UUIDs.
8
9With 100% test coverage and benchmarks out of box.
10
11Supported versions:
12* Version 1, based on timestamp and MAC address (RFC 4122)
13* Version 2, based on timestamp, MAC address and POSIX UID/GID (DCE 1.1)
14* Version 3, based on MD5 hashing (RFC 4122)
15* Version 4, based on random numbers (RFC 4122)
16* Version 5, based on SHA-1 hashing (RFC 4122)
17
18## Installation
19
20Use the `go` command:
21
22 $ go get github.com/satori/go.uuid
23
24## Requirements
25
26UUID package requires Go >= 1.2.
27
28## Example
29
30```go
31package main
32
33import (
34 "fmt"
35 "github.com/satori/go.uuid"
36)
37
38func main() {
39 // Creating UUID Version 4
40 u1 := uuid.NewV4()
41 fmt.Printf("UUIDv4: %s\n", u1)
42
43 // Parsing UUID from string input
44 u2, err := uuid.FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
45 if err != nil {
46 fmt.Printf("Something gone wrong: %s", err)
47 }
48 fmt.Printf("Successfully parsed: %s", u2)
49}
50```
51
52## Documentation
53
54[Documentation](http://godoc.org/github.com/satori/go.uuid) is hosted at GoDoc project.
55
56## Links
57* [RFC 4122](http://tools.ietf.org/html/rfc4122)
58* [DCE 1.1: Authentication and Security Services](http://pubs.opengroup.org/onlinepubs/9696989899/chap5.htm#tagcjh_08_02_01_01)
59
60## Copyright
61
62Copyright (C) 2013-2018 by Maxim Bublis <b@codemonkey.ru>.
63
64UUID package released under MIT License.
65See [LICENSE](https://github.com/satori/go.uuid/blob/master/LICENSE) for details.
diff --git a/vendor/github.com/satori/go.uuid/codec.go b/vendor/github.com/satori/go.uuid/codec.go
new file mode 100644
index 0000000..656892c
--- /dev/null
+++ b/vendor/github.com/satori/go.uuid/codec.go
@@ -0,0 +1,206 @@
1// Copyright (C) 2013-2018 by Maxim Bublis <b@codemonkey.ru>
2//
3// Permission is hereby granted, free of charge, to any person obtaining
4// a copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to
8// permit persons to whom the Software is furnished to do so, subject to
9// the following conditions:
10//
11// The above copyright notice and this permission notice shall be
12// included in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22package uuid
23
24import (
25 "bytes"
26 "encoding/hex"
27 "fmt"
28)
29
30// FromBytes returns UUID converted from raw byte slice input.
31// It will return error if the slice isn't 16 bytes long.
32func FromBytes(input []byte) (u UUID, err error) {
33 err = u.UnmarshalBinary(input)
34 return
35}
36
37// FromBytesOrNil returns UUID converted from raw byte slice input.
38// Same behavior as FromBytes, but returns a Nil UUID on error.
39func FromBytesOrNil(input []byte) UUID {
40 uuid, err := FromBytes(input)
41 if err != nil {
42 return Nil
43 }
44 return uuid
45}
46
47// FromString returns UUID parsed from string input.
48// Input is expected in a form accepted by UnmarshalText.
49func FromString(input string) (u UUID, err error) {
50 err = u.UnmarshalText([]byte(input))
51 return
52}
53
54// FromStringOrNil returns UUID parsed from string input.
55// Same behavior as FromString, but returns a Nil UUID on error.
56func FromStringOrNil(input string) UUID {
57 uuid, err := FromString(input)
58 if err != nil {
59 return Nil
60 }
61 return uuid
62}
63
64// MarshalText implements the encoding.TextMarshaler interface.
65// The encoding is the same as returned by String.
66func (u UUID) MarshalText() (text []byte, err error) {
67 text = []byte(u.String())
68 return
69}
70
71// UnmarshalText implements the encoding.TextUnmarshaler interface.
72// Following formats are supported:
73// "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
74// "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}",
75// "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8"
76// "6ba7b8109dad11d180b400c04fd430c8"
77// ABNF for supported UUID text representation follows:
78// uuid := canonical | hashlike | braced | urn
79// plain := canonical | hashlike
80// canonical := 4hexoct '-' 2hexoct '-' 2hexoct '-' 6hexoct
81// hashlike := 12hexoct
82// braced := '{' plain '}'
83// urn := URN ':' UUID-NID ':' plain
84// URN := 'urn'
85// UUID-NID := 'uuid'
86// 12hexoct := 6hexoct 6hexoct
87// 6hexoct := 4hexoct 2hexoct
88// 4hexoct := 2hexoct 2hexoct
89// 2hexoct := hexoct hexoct
90// hexoct := hexdig hexdig
91// hexdig := '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' |
92// 'a' | 'b' | 'c' | 'd' | 'e' | 'f' |
93// 'A' | 'B' | 'C' | 'D' | 'E' | 'F'
94func (u *UUID) UnmarshalText(text []byte) (err error) {
95 switch len(text) {
96 case 32:
97 return u.decodeHashLike(text)
98 case 36:
99 return u.decodeCanonical(text)
100 case 38:
101 return u.decodeBraced(text)
102 case 41:
103 fallthrough
104 case 45:
105 return u.decodeURN(text)
106 default:
107 return fmt.Errorf("uuid: incorrect UUID length: %s", text)
108 }
109}
110
111// decodeCanonical decodes UUID string in format
112// "6ba7b810-9dad-11d1-80b4-00c04fd430c8".
113func (u *UUID) decodeCanonical(t []byte) (err error) {
114 if t[8] != '-' || t[13] != '-' || t[18] != '-' || t[23] != '-' {
115 return fmt.Errorf("uuid: incorrect UUID format %s", t)
116 }
117
118 src := t[:]
119 dst := u[:]
120
121 for i, byteGroup := range byteGroups {
122 if i > 0 {
123 src = src[1:] // skip dash
124 }
125 _, err = hex.Decode(dst[:byteGroup/2], src[:byteGroup])
126 if err != nil {
127 return
128 }
129 src = src[byteGroup:]
130 dst = dst[byteGroup/2:]
131 }
132
133 return
134}
135
136// decodeHashLike decodes UUID string in format
137// "6ba7b8109dad11d180b400c04fd430c8".
138func (u *UUID) decodeHashLike(t []byte) (err error) {
139 src := t[:]
140 dst := u[:]
141
142 if _, err = hex.Decode(dst, src); err != nil {
143 return err
144 }
145 return
146}
147
148// decodeBraced decodes UUID string in format
149// "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}" or in format
150// "{6ba7b8109dad11d180b400c04fd430c8}".
151func (u *UUID) decodeBraced(t []byte) (err error) {
152 l := len(t)
153
154 if t[0] != '{' || t[l-1] != '}' {
155 return fmt.Errorf("uuid: incorrect UUID format %s", t)
156 }
157
158 return u.decodePlain(t[1 : l-1])
159}
160
161// decodeURN decodes UUID string in format
162// "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8" or in format
163// "urn:uuid:6ba7b8109dad11d180b400c04fd430c8".
164func (u *UUID) decodeURN(t []byte) (err error) {
165 total := len(t)
166
167 urn_uuid_prefix := t[:9]
168
169 if !bytes.Equal(urn_uuid_prefix, urnPrefix) {
170 return fmt.Errorf("uuid: incorrect UUID format: %s", t)
171 }
172
173 return u.decodePlain(t[9:total])
174}
175
176// decodePlain decodes UUID string in canonical format
177// "6ba7b810-9dad-11d1-80b4-00c04fd430c8" or in hash-like format
178// "6ba7b8109dad11d180b400c04fd430c8".
179func (u *UUID) decodePlain(t []byte) (err error) {
180 switch len(t) {
181 case 32:
182 return u.decodeHashLike(t)
183 case 36:
184 return u.decodeCanonical(t)
185 default:
186 return fmt.Errorf("uuid: incorrrect UUID length: %s", t)
187 }
188}
189
190// MarshalBinary implements the encoding.BinaryMarshaler interface.
191func (u UUID) MarshalBinary() (data []byte, err error) {
192 data = u.Bytes()
193 return
194}
195
196// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
197// It will return error if the slice isn't 16 bytes long.
198func (u *UUID) UnmarshalBinary(data []byte) (err error) {
199 if len(data) != Size {
200 err = fmt.Errorf("uuid: UUID must be exactly 16 bytes long, got %d bytes", len(data))
201 return
202 }
203 copy(u[:], data)
204
205 return
206}
diff --git a/vendor/github.com/satori/go.uuid/generator.go b/vendor/github.com/satori/go.uuid/generator.go
new file mode 100644
index 0000000..3f2f1da
--- /dev/null
+++ b/vendor/github.com/satori/go.uuid/generator.go
@@ -0,0 +1,239 @@
1// Copyright (C) 2013-2018 by Maxim Bublis <b@codemonkey.ru>
2//
3// Permission is hereby granted, free of charge, to any person obtaining
4// a copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to
8// permit persons to whom the Software is furnished to do so, subject to
9// the following conditions:
10//
11// The above copyright notice and this permission notice shall be
12// included in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22package uuid
23
24import (
25 "crypto/md5"
26 "crypto/rand"
27 "crypto/sha1"
28 "encoding/binary"
29 "hash"
30 "net"
31 "os"
32 "sync"
33 "time"
34)
35
36// Difference in 100-nanosecond intervals between
37// UUID epoch (October 15, 1582) and Unix epoch (January 1, 1970).
38const epochStart = 122192928000000000
39
40var (
41 global = newDefaultGenerator()
42
43 epochFunc = unixTimeFunc
44 posixUID = uint32(os.Getuid())
45 posixGID = uint32(os.Getgid())
46)
47
48// NewV1 returns UUID based on current timestamp and MAC address.
49func NewV1() UUID {
50 return global.NewV1()
51}
52
53// NewV2 returns DCE Security UUID based on POSIX UID/GID.
54func NewV2(domain byte) UUID {
55 return global.NewV2(domain)
56}
57
58// NewV3 returns UUID based on MD5 hash of namespace UUID and name.
59func NewV3(ns UUID, name string) UUID {
60 return global.NewV3(ns, name)
61}
62
63// NewV4 returns random generated UUID.
64func NewV4() UUID {
65 return global.NewV4()
66}
67
68// NewV5 returns UUID based on SHA-1 hash of namespace UUID and name.
69func NewV5(ns UUID, name string) UUID {
70 return global.NewV5(ns, name)
71}
72
73// Generator provides interface for generating UUIDs.
74type Generator interface {
75 NewV1() UUID
76 NewV2(domain byte) UUID
77 NewV3(ns UUID, name string) UUID
78 NewV4() UUID
79 NewV5(ns UUID, name string) UUID
80}
81
82// Default generator implementation.
83type generator struct {
84 storageOnce sync.Once
85 storageMutex sync.Mutex
86
87 lastTime uint64
88 clockSequence uint16
89 hardwareAddr [6]byte
90}
91
92func newDefaultGenerator() Generator {
93 return &generator{}
94}
95
96// NewV1 returns UUID based on current timestamp and MAC address.
97func (g *generator) NewV1() UUID {
98 u := UUID{}
99
100 timeNow, clockSeq, hardwareAddr := g.getStorage()
101
102 binary.BigEndian.PutUint32(u[0:], uint32(timeNow))
103 binary.BigEndian.PutUint16(u[4:], uint16(timeNow>>32))
104 binary.BigEndian.PutUint16(u[6:], uint16(timeNow>>48))
105 binary.BigEndian.PutUint16(u[8:], clockSeq)
106
107 copy(u[10:], hardwareAddr)
108
109 u.SetVersion(V1)
110 u.SetVariant(VariantRFC4122)
111
112 return u
113}
114
115// NewV2 returns DCE Security UUID based on POSIX UID/GID.
116func (g *generator) NewV2(domain byte) UUID {
117 u := UUID{}
118
119 timeNow, clockSeq, hardwareAddr := g.getStorage()
120
121 switch domain {
122 case DomainPerson:
123 binary.BigEndian.PutUint32(u[0:], posixUID)
124 case DomainGroup:
125 binary.BigEndian.PutUint32(u[0:], posixGID)
126 }
127
128 binary.BigEndian.PutUint16(u[4:], uint16(timeNow>>32))
129 binary.BigEndian.PutUint16(u[6:], uint16(timeNow>>48))
130 binary.BigEndian.PutUint16(u[8:], clockSeq)
131 u[9] = domain
132
133 copy(u[10:], hardwareAddr)
134
135 u.SetVersion(V2)
136 u.SetVariant(VariantRFC4122)
137
138 return u
139}
140
141// NewV3 returns UUID based on MD5 hash of namespace UUID and name.
142func (g *generator) NewV3(ns UUID, name string) UUID {
143 u := newFromHash(md5.New(), ns, name)
144 u.SetVersion(V3)
145 u.SetVariant(VariantRFC4122)
146
147 return u
148}
149
150// NewV4 returns random generated UUID.
151func (g *generator) NewV4() UUID {
152 u := UUID{}
153 g.safeRandom(u[:])
154 u.SetVersion(V4)
155 u.SetVariant(VariantRFC4122)
156
157 return u
158}
159
160// NewV5 returns UUID based on SHA-1 hash of namespace UUID and name.
161func (g *generator) NewV5(ns UUID, name string) UUID {
162 u := newFromHash(sha1.New(), ns, name)
163 u.SetVersion(V5)
164 u.SetVariant(VariantRFC4122)
165
166 return u
167}
168
169func (g *generator) initStorage() {
170 g.initClockSequence()
171 g.initHardwareAddr()
172}
173
174func (g *generator) initClockSequence() {
175 buf := make([]byte, 2)
176 g.safeRandom(buf)
177 g.clockSequence = binary.BigEndian.Uint16(buf)
178}
179
180func (g *generator) initHardwareAddr() {
181 interfaces, err := net.Interfaces()
182 if err == nil {
183 for _, iface := range interfaces {
184 if len(iface.HardwareAddr) >= 6 {
185 copy(g.hardwareAddr[:], iface.HardwareAddr)
186 return
187 }
188 }
189 }
190
191 // Initialize hardwareAddr randomly in case
192 // of real network interfaces absence
193 g.safeRandom(g.hardwareAddr[:])
194
195 // Set multicast bit as recommended in RFC 4122
196 g.hardwareAddr[0] |= 0x01
197}
198
199func (g *generator) safeRandom(dest []byte) {
200 if _, err := rand.Read(dest); err != nil {
201 panic(err)
202 }
203}
204
205// Returns UUID v1/v2 storage state.
206// Returns epoch timestamp, clock sequence, and hardware address.
207func (g *generator) getStorage() (uint64, uint16, []byte) {
208 g.storageOnce.Do(g.initStorage)
209
210 g.storageMutex.Lock()
211 defer g.storageMutex.Unlock()
212
213 timeNow := epochFunc()
214 // Clock changed backwards since last UUID generation.
215 // Should increase clock sequence.
216 if timeNow <= g.lastTime {
217 g.clockSequence++
218 }
219 g.lastTime = timeNow
220
221 return timeNow, g.clockSequence, g.hardwareAddr[:]
222}
223
224// Returns difference in 100-nanosecond intervals between
225// UUID epoch (October 15, 1582) and current time.
226// This is default epoch calculation function.
227func unixTimeFunc() uint64 {
228 return epochStart + uint64(time.Now().UnixNano()/100)
229}
230
231// Returns UUID based on hashing of namespace UUID and name.
232func newFromHash(h hash.Hash, ns UUID, name string) UUID {
233 u := UUID{}
234 h.Write(ns[:])
235 h.Write([]byte(name))
236 copy(u[:], h.Sum(nil))
237
238 return u
239}
diff --git a/vendor/github.com/satori/go.uuid/sql.go b/vendor/github.com/satori/go.uuid/sql.go
new file mode 100644
index 0000000..56759d3
--- /dev/null
+++ b/vendor/github.com/satori/go.uuid/sql.go
@@ -0,0 +1,78 @@
1// Copyright (C) 2013-2018 by Maxim Bublis <b@codemonkey.ru>
2//
3// Permission is hereby granted, free of charge, to any person obtaining
4// a copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to
8// permit persons to whom the Software is furnished to do so, subject to
9// the following conditions:
10//
11// The above copyright notice and this permission notice shall be
12// included in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22package uuid
23
24import (
25 "database/sql/driver"
26 "fmt"
27)
28
29// Value implements the driver.Valuer interface.
30func (u UUID) Value() (driver.Value, error) {
31 return u.String(), nil
32}
33
34// Scan implements the sql.Scanner interface.
35// A 16-byte slice is handled by UnmarshalBinary, while
36// a longer byte slice or a string is handled by UnmarshalText.
37func (u *UUID) Scan(src interface{}) error {
38 switch src := src.(type) {
39 case []byte:
40 if len(src) == Size {
41 return u.UnmarshalBinary(src)
42 }
43 return u.UnmarshalText(src)
44
45 case string:
46 return u.UnmarshalText([]byte(src))
47 }
48
49 return fmt.Errorf("uuid: cannot convert %T to UUID", src)
50}
51
52// NullUUID can be used with the standard sql package to represent a
53// UUID value that can be NULL in the database
54type NullUUID struct {
55 UUID UUID
56 Valid bool
57}
58
59// Value implements the driver.Valuer interface.
60func (u NullUUID) Value() (driver.Value, error) {
61 if !u.Valid {
62 return nil, nil
63 }
64 // Delegate to UUID Value function
65 return u.UUID.Value()
66}
67
68// Scan implements the sql.Scanner interface.
69func (u *NullUUID) Scan(src interface{}) error {
70 if src == nil {
71 u.UUID, u.Valid = Nil, false
72 return nil
73 }
74
75 // Delegate to UUID Scan function
76 u.Valid = true
77 return u.UUID.Scan(src)
78}
diff --git a/vendor/github.com/satori/go.uuid/uuid.go b/vendor/github.com/satori/go.uuid/uuid.go
new file mode 100644
index 0000000..a2b8e2c
--- /dev/null
+++ b/vendor/github.com/satori/go.uuid/uuid.go
@@ -0,0 +1,161 @@
1// Copyright (C) 2013-2018 by Maxim Bublis <b@codemonkey.ru>
2//
3// Permission is hereby granted, free of charge, to any person obtaining
4// a copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to
8// permit persons to whom the Software is furnished to do so, subject to
9// the following conditions:
10//
11// The above copyright notice and this permission notice shall be
12// included in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22// Package uuid provides implementation of Universally Unique Identifier (UUID).
23// Supported versions are 1, 3, 4 and 5 (as specified in RFC 4122) and
24// version 2 (as specified in DCE 1.1).
25package uuid
26
27import (
28 "bytes"
29 "encoding/hex"
30)
31
32// Size of a UUID in bytes.
33const Size = 16
34
35// UUID representation compliant with specification
36// described in RFC 4122.
37type UUID [Size]byte
38
39// UUID versions
40const (
41 _ byte = iota
42 V1
43 V2
44 V3
45 V4
46 V5
47)
48
49// UUID layout variants.
50const (
51 VariantNCS byte = iota
52 VariantRFC4122
53 VariantMicrosoft
54 VariantFuture
55)
56
57// UUID DCE domains.
58const (
59 DomainPerson = iota
60 DomainGroup
61 DomainOrg
62)
63
64// String parse helpers.
65var (
66 urnPrefix = []byte("urn:uuid:")
67 byteGroups = []int{8, 4, 4, 4, 12}
68)
69
70// Nil is special form of UUID that is specified to have all
71// 128 bits set to zero.
72var Nil = UUID{}
73
74// Predefined namespace UUIDs.
75var (
76 NamespaceDNS = Must(FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8"))
77 NamespaceURL = Must(FromString("6ba7b811-9dad-11d1-80b4-00c04fd430c8"))
78 NamespaceOID = Must(FromString("6ba7b812-9dad-11d1-80b4-00c04fd430c8"))
79 NamespaceX500 = Must(FromString("6ba7b814-9dad-11d1-80b4-00c04fd430c8"))
80)
81
82// Equal returns true if u1 and u2 equals, otherwise returns false.
83func Equal(u1 UUID, u2 UUID) bool {
84 return bytes.Equal(u1[:], u2[:])
85}
86
87// Version returns algorithm version used to generate UUID.
88func (u UUID) Version() byte {
89 return u[6] >> 4
90}
91
92// Variant returns UUID layout variant.
93func (u UUID) Variant() byte {
94 switch {
95 case (u[8] >> 7) == 0x00:
96 return VariantNCS
97 case (u[8] >> 6) == 0x02:
98 return VariantRFC4122
99 case (u[8] >> 5) == 0x06:
100 return VariantMicrosoft
101 case (u[8] >> 5) == 0x07:
102 fallthrough
103 default:
104 return VariantFuture
105 }
106}
107
108// Bytes returns bytes slice representation of UUID.
109func (u UUID) Bytes() []byte {
110 return u[:]
111}
112
113// Returns canonical string representation of UUID:
114// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
115func (u UUID) String() string {
116 buf := make([]byte, 36)
117
118 hex.Encode(buf[0:8], u[0:4])
119 buf[8] = '-'
120 hex.Encode(buf[9:13], u[4:6])
121 buf[13] = '-'
122 hex.Encode(buf[14:18], u[6:8])
123 buf[18] = '-'
124 hex.Encode(buf[19:23], u[8:10])
125 buf[23] = '-'
126 hex.Encode(buf[24:], u[10:])
127
128 return string(buf)
129}
130
131// SetVersion sets version bits.
132func (u *UUID) SetVersion(v byte) {
133 u[6] = (u[6] & 0x0f) | (v << 4)
134}
135
136// SetVariant sets variant bits.
137func (u *UUID) SetVariant(v byte) {
138 switch v {
139 case VariantNCS:
140 u[8] = (u[8]&(0xff>>1) | (0x00 << 7))
141 case VariantRFC4122:
142 u[8] = (u[8]&(0xff>>2) | (0x02 << 6))
143 case VariantMicrosoft:
144 u[8] = (u[8]&(0xff>>3) | (0x06 << 5))
145 case VariantFuture:
146 fallthrough
147 default:
148 u[8] = (u[8]&(0xff>>3) | (0x07 << 5))
149 }
150}
151
152// Must is a helper that wraps a call to a function returning (UUID, error)
153// and panics if the error is non-nil. It is intended for use in variable
154// initializations such as
155// var packageUUID = uuid.Must(uuid.FromString("123e4567-e89b-12d3-a456-426655440000"));
156func Must(u UUID, err error) UUID {
157 if err != nil {
158 panic(err)
159 }
160 return u
161}