passed/storage/storage.go

41 lines
757 B
Go
Raw Normal View History

2024-10-29 23:08:11 +00:00
package storage
import (
"errors"
"log"
"os"
"strings"
"time"
)
var (
ErrNotFound = errors.New("password not found")
ErrFull = errors.New("storage is filled")
)
type entry struct {
password []byte
expiresAt time.Time
}
type Store interface {
CreatePassword(password []byte, expiresAt time.Time) (string, error)
GetPassword(id string) ([]byte, error)
HasPassword(id string) (bool, error)
2024-10-29 23:21:25 +00:00
Close() error
2024-10-29 23:08:11 +00:00
}
func NewStore() (Store, error) {
storeType := os.Getenv("PASSED_STORE_TYPE")
storeType = strings.ToLower(storeType)
switch storeType {
case "ram":
2024-10-29 23:25:53 +00:00
return NewRamStore(20 * time.Second), nil
2024-10-29 23:08:11 +00:00
default:
log.Printf("No PASSED_STORE_TYPE provided, defaulting to memory store.")
2024-10-29 23:25:53 +00:00
return NewRamStore(20 * time.Second), nil
2024-10-29 23:08:11 +00:00
}
}