mirror of
https://github.com/lus/pasty.git
synced 2023-08-10 21:13:09 +03:00
20 lines
355 B
Go
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
|
|
}
|
|
}
|
|
}
|