Fix error on zero expiry

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-06-10 20:36:11 +02:00
parent e320307768
commit fa710e3716
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5
2 changed files with 11 additions and 3 deletions

View file

@ -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,
} }

View file

@ -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")
} }