2
0

support unformatted uuid hex string.

adds the abiility to support uuids in the form:
000102030405060708090a0b0c0d0e0f
This commit is contained in:
James Lawrence
2020-07-06 11:27:15 -04:00
parent efe4704c57
commit 5576567c19
2 changed files with 12 additions and 2 deletions
+8 -2
View File
@@ -100,10 +100,16 @@ func (src *UUID) AssignTo(dst interface{}) error {
// parseUUID converts a string UUID in standard form to a byte array.
func parseUUID(src string) (dst [16]byte, err error) {
if len(src) < 36 {
switch len(src) {
case 36:
src = src[0:8] + src[9:13] + src[14:18] + src[19:23] + src[24:]
case 32:
// dashes already stripped, assume valid
default:
// assume invalid.
return dst, errors.Errorf("cannot parse UUID %v", src)
}
src = src[0:8] + src[9:13] + src[14:18] + src[19:23] + src[24:]
buf, err := hex.DecodeString(src)
if err != nil {
return dst, err
+4
View File
@@ -46,6 +46,10 @@ func TestUUIDSet(t *testing.T) {
source: "00010203-0405-0607-0809-0a0b0c0d0e0f",
result: pgtype.UUID{Bytes: [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, Status: pgtype.Present},
},
{
source: "000102030405060708090a0b0c0d0e0f",
result: pgtype.UUID{Bytes: [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, Status: pgtype.Present},
},
}
for i, tt := range successfulTests {