TruncateID returns a shorthand version of a string identifier for presentation. For convenience, it accepts both digests ("sha256:xxxx") and IDs without an algorithm prefix. It truncates the algorithm (if any) before truncating the ID. The length of the truncated ID is currently fixed, but users sho
(id string)
| 24 | // which case an "ambiguous result" error is produced. In case of a collision, |
| 25 | // the caller should try with a longer prefix or the full-length ID. |
| 26 | func TruncateID(id string) string { |
| 27 | if i := strings.IndexRune(id, ':'); i >= 0 { |
| 28 | id = id[i+1:] |
| 29 | } |
| 30 | if len(id) > shortLen { |
| 31 | id = id[:shortLen] |
| 32 | } |
| 33 | return id |
| 34 | } |
| 35 | |
| 36 | // GenerateRandomID returns a unique, 64-character ID consisting of a-z, 0-9. |
| 37 | // It guarantees that the ID, when truncated ([TruncateID]) does not consist |
no outgoing calls
searching dependent graphs…