1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00
pasty/internal/storage/id_generation.go

21 lines
360 B
Go
Raw Normal View History

package storage
import (
2021-04-15 21:15:42 +03:00
"github.com/lus/pasty/internal/config"
2021-04-15 20:26:17 +03:00
"github.com/lus/pasty/internal/utils"
)
// AcquireID generates a new unique ID
func AcquireID() (string, error) {
for {
2021-04-15 21:15:42 +03:00
id := utils.RandomString(config.Current.IDLength)
paste, err := Current.Get(id)
if err != nil {
return "", err
}
if paste == nil {
return id, nil
}
}
}