2017-08-03 08:13:53 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2023-06-09 19:36:01 -04:00
|
|
|
"time"
|
2017-08-03 08:13:53 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var errSecretNotFound = errors.New("Secret not found")
|
|
|
|
|
|
|
|
type storage interface {
|
2023-06-09 19:36:01 -04:00
|
|
|
Create(secret string, expireIn time.Duration) (string, error)
|
2017-08-03 08:13:53 -04:00
|
|
|
ReadAndDestroy(id string) (string, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getStorageByType(t string) (storage, error) {
|
|
|
|
switch t {
|
|
|
|
case "mem":
|
|
|
|
return newStorageMem(), nil
|
|
|
|
case "redis":
|
|
|
|
return newStorageRedis()
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("Storage type %q not found", t)
|
|
|
|
}
|
|
|
|
}
|