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
|
|
|
)
|
|
|
|
|
2023-10-04 16:53:29 -04:00
|
|
|
var errSecretNotFound = errors.New("secret not found")
|
2017-08-03 08:13:53 -04:00
|
|
|
|
|
|
|
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:
|
2023-10-04 16:53:29 -04:00
|
|
|
return nil, fmt.Errorf("storage type %q not found", t)
|
2017-08-03 08:13:53 -04:00
|
|
|
}
|
|
|
|
}
|