passed/storage/storage.go

39 lines
672 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)
}
func NewStore() (Store, error) {
storeType := os.Getenv("PASSED_STORE_TYPE")
storeType = strings.ToLower(storeType)
switch storeType {
case "ram":
return NewRamStore(), nil
default:
log.Printf("No PASSED_STORE_TYPE provided, defaulting to memory store.")
return NewRamStore(), nil
}
}