UnmarshalText implements the encoding.TextUnmarshaler interface. Following formats are supported: "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}", "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8" "6ba7b8109dad11d180b400c04fd430c8" "{6ba7b8109dad11d180b400c04fd43
(text []byte)
| 112 | // braced := '{' plain '}' | '{' hashlike '}' |
| 113 | // urn := URN ':' UUID-NID ':' plain |
| 114 | func (u *UUID) UnmarshalText(text []byte) error { |
| 115 | switch len(text) { |
| 116 | case 32: |
| 117 | return u.decodeHashLike(text) |
| 118 | case 34, 38: |
| 119 | return u.decodeBraced(text) |
| 120 | case 36: |
| 121 | return u.decodeCanonical(text) |
| 122 | case 41, 45: |
| 123 | return u.decodeURN(text) |
| 124 | default: |
| 125 | // Postgres allows for an extended dash placement scheme. We'll eventually support those explicitly, but for |
| 126 | // now, we'll just "support" them all by removing the dashes so that the UUID is in a dash-less state. |
| 127 | shortenedText := bytes.ReplaceAll(text, []byte{'-'}, nil) |
| 128 | switch len(shortenedText) { |
| 129 | case 32: |
| 130 | return u.decodeHashLike(shortenedText) |
| 131 | case 34, 38: |
| 132 | return u.decodeBraced(shortenedText) |
| 133 | case 36: |
| 134 | return u.decodeCanonical(shortenedText) |
| 135 | case 41, 45: |
| 136 | return u.decodeURN(shortenedText) |
| 137 | } |
| 138 | return fmt.Errorf("uuid: incorrect UUID length: %s", text) |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | // decodeCanonical decodes UUID strings that are formatted as defined in RFC-4122 (section 3): |
| 143 | // "6ba7b810-9dad-11d1-80b4-00c04fd430c8". |
no test coverage detected