2017-08-03 12:13:53 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2023-06-09 23:36:01 +00:00
|
|
|
"time"
|
2017-08-03 12:13:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var errSecretNotFound = errors.New("Secret not found")
|
|
|
|
|
|
|
|
type storage interface {
|
2023-06-09 23:36:01 +00:00
|
|
|
Create(secret string, expireIn time.Duration) (string, error)
|
2017-08-03 12:13:53 +00: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)
|
|
|
|
}
|
|
|
|
}
|