Fix error on zero expiry
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
e320307768
commit
fa710e3716
2 changed files with 11 additions and 3 deletions
|
@ -22,9 +22,17 @@ func newStorageMem() storage {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s storageMem) Create(secret string, expireIn time.Duration) (string, error) {
|
func (s storageMem) Create(secret string, expireIn time.Duration) (string, error) {
|
||||||
id := uuid.Must(uuid.NewV4()).String()
|
var (
|
||||||
|
expire time.Time
|
||||||
|
id = uuid.Must(uuid.NewV4()).String()
|
||||||
|
)
|
||||||
|
|
||||||
|
if expireIn > 0 {
|
||||||
|
expire = time.Now().Add(expireIn)
|
||||||
|
}
|
||||||
|
|
||||||
s.store[id] = memStorageSecret{
|
s.store[id] = memStorageSecret{
|
||||||
Expiry: time.Now().Add(expireIn),
|
Expiry: expire,
|
||||||
Secret: secret,
|
Secret: secret,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ func newStorageRedis() (storage, error) {
|
||||||
|
|
||||||
func (s storageRedis) Create(secret string, expireIn time.Duration) (string, error) {
|
func (s storageRedis) Create(secret string, expireIn time.Duration) (string, error) {
|
||||||
id := uuid.Must(uuid.NewV4()).String()
|
id := uuid.Must(uuid.NewV4()).String()
|
||||||
err := s.conn.SetEx(context.Background(), s.redisKey(id), secret, expireIn).Err()
|
err := s.conn.Set(context.Background(), s.redisKey(id), secret, expireIn).Err()
|
||||||
|
|
||||||
return id, errors.Wrap(err, "writing redis key")
|
return id, errors.Wrap(err, "writing redis key")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue