30 lines
562 B
Go
30 lines
562 B
Go
package storage
|
|
|
|
import (
|
|
"errors"
|
|
"math/rand/v2"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
ErrNotFound = errors.New("password not found")
|
|
ErrFull = errors.New("storage is filled")
|
|
)
|
|
|
|
type Store interface {
|
|
Create(password []byte, expiresAt time.Time) (string, error)
|
|
Get(id string) ([]byte, error)
|
|
Delete(id string) error
|
|
ClearExpired() error
|
|
}
|
|
|
|
func generateId(length int) string {
|
|
runes := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
|
|
str := make([]rune, length)
|
|
for i := range str {
|
|
str[i] = runes[rand.IntN(len(runes))]
|
|
}
|
|
|
|
return string(str)
|
|
}
|