30 lines
674 B
Go
30 lines
674 B
Go
package author
|
|
|
|
import "strconv"
|
|
|
|
const DeletedName = "Deleted user"
|
|
|
|
const DeletedSlugPrefix = "deleted-user-"
|
|
|
|
func DeletedSlug(id uint32) string {
|
|
return DeletedSlugPrefix + strconv.FormatUint(uint64(id), 10)
|
|
}
|
|
|
|
func DeletedSlugAttempt(id uint32, attempt int) string {
|
|
if attempt <= 1 {
|
|
return DeletedSlug(id)
|
|
}
|
|
return DeletedSlug(id) + "-" + strconv.Itoa(attempt)
|
|
}
|
|
|
|
func IsReservedSlug(candidate string) bool {
|
|
return len(candidate) >= len(DeletedSlugPrefix) && candidate[:len(DeletedSlugPrefix)] == DeletedSlugPrefix
|
|
}
|
|
|
|
func avoidReserved(candidate string) string {
|
|
if IsReservedSlug(candidate) {
|
|
return FallbackSlug + "-" + candidate
|
|
}
|
|
return candidate
|
|
}
|