Skip to content

Commit

Permalink
move constants
Browse files Browse the repository at this point in the history
Signed-off-by: Amir Malka <[email protected]>
  • Loading branch information
amirmalka committed Sep 12, 2023
1 parent a238b4d commit e1b8c85
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions names/slugs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const (
// "hashlessFormat + hashLeading + hashTrailing"
slugFormat = "%s-%s-%s"
slugHashLength = 4
// slugHashesLength is a length of the hash-based identifiers (-xxxx-xxxx) in the slug string
slugHashesLength = slugHashLength*2 + 2
maxHashlessStringLength = maxDNSSubdomainLength - slugHashesLength

// imageIDSlugFormat is a format of the Image ID slug
imageIDSlugFormat = "%s-%s"
Expand Down Expand Up @@ -219,12 +222,8 @@ func StringToSlug(str string) (string, error) {
return "", err
}

// limit the length of the string so that the slug is not longer than the maximum DNS Subdomain length characters
const slugHashesLength = slugHashLength*2 + 2
const maxStrLength = maxDNSSubdomainLength - slugHashesLength

if len(sanitizedStr) >= maxStrLength {
sanitizedStr = sanitizedStr[:maxStrLength]
if len(sanitizedStr) >= maxHashlessStringLength {
sanitizedStr = sanitizedStr[:maxHashlessStringLength]
}

slug := fmt.Sprintf(slugFormat, sanitizedStr, leadingDigest, trailingDigest)
Expand Down

0 comments on commit e1b8c85

Please sign in to comment.