passed/storage/storage.go
2024-10-30 00:25:53 +01:00

39 lines
719 B
Go

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