mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-22 05:40:50 +02:00
24 lines
506 B
Go
24 lines
506 B
Go
![]() |
package container
|
||
|
|
||
|
import "strings"
|
||
|
|
||
|
// ShortID returns the 12-character (hex) short version of an image ID hash, removing any "sha256:" prefix if present
|
||
|
func ShortID(imageID string) (short string) {
|
||
|
prefixSep := strings.IndexRune(imageID, ':')
|
||
|
offset := 0
|
||
|
length := 12
|
||
|
if prefixSep >= 0 {
|
||
|
if imageID[0:prefixSep] == "sha256" {
|
||
|
offset = prefixSep + 1
|
||
|
} else {
|
||
|
length += prefixSep + 1
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if len(imageID) >= offset+length {
|
||
|
return imageID[offset : offset+length]
|
||
|
}
|
||
|
|
||
|
return imageID
|
||
|
}
|