Improved anime view on characters

This commit is contained in:
2019-11-19 11:39:20 +09:00
parent 4fbe73a1d0
commit b8b2fb9354
14 changed files with 135 additions and 92 deletions

View File

@ -1,4 +1,35 @@
package arn
import (
"errors"
"strings"
shortid "github.com/ventu-io/go-shortid"
)
// ID is used for object identification and is simply a string.
type ID = string
// GenerateID generates a unique ID for a given collection.
func GenerateID(collection string) ID {
id, _ := shortid.Generate()
// Retry until we find an unused ID
retry := 0
for {
_, err := DB.Get(collection, id)
if err != nil && strings.Contains(err.Error(), "not found") {
return id
}
retry++
if retry > 10 {
panic(errors.New("Can't generate unique ID"))
}
id, _ = shortid.Generate()
}
}