support unformatted uuid hex string.
adds the abiility to support uuids in the form: 000102030405060708090a0b0c0d0e0f
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user