1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00
pasty/internal/pastes/id_generation.go
2023-06-07 19:51:54 +02:00

20 lines
355 B
Go

package pastes
import (
"context"
"github.com/lus/pasty/internal/randx"
)
func GenerateID(ctx context.Context, repo Repository, charset string, length int) (string, error) {
for {
id := randx.String(charset, length)
existing, err := repo.FindByID(ctx, id)
if err != nil {
return "", err
}
if existing == nil {
return id, nil
}
}
}