passed/storage/storage.go

31 lines
562 B
Go
Raw Normal View History

2024-10-29 23:08:11 +00:00
package storage
import (
"errors"
2024-10-30 09:09:18 +00:00
"math/rand/v2"
2024-10-29 23:08:11 +00:00
"time"
)
var (
ErrNotFound = errors.New("password not found")
ErrFull = errors.New("storage is filled")
)
type Store interface {
2024-10-30 10:17:48 +00:00
Create(password []byte, expiresAt time.Time) (string, error)
Get(id string) ([]byte, error)
Delete(id string) error
2024-10-30 10:47:17 +00:00
ClearExpired() error
2024-10-29 23:08:11 +00:00
}
2024-10-30 09:09:18 +00:00
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)
}