expiry can be taken from options or record (#1928)

This commit is contained in:
Dominic Wong 2020-08-11 18:11:18 +01:00 committed by GitHub
parent b6e1c7ac99
commit 69a53e8070
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -422,13 +422,14 @@ func (s *sqlStore) Write(r *store.Record, opts ...store.WriteOption) error {
metadata[k] = v
}
if r.Expiry != 0 {
_, err = st.Exec(r.Key, r.Value, metadata, time.Now().Add(r.Expiry))
} else {
_, err = st.Exec(r.Key, r.Value, metadata, nil)
var expiry time.Time
// expiry from options takes precedence
if !options.Expiry.IsZero() {
expiry = options.Expiry
} else if r.Expiry != 0 {
expiry = time.Now().Add(r.Expiry)
}
if err != nil {
if _, err := st.Exec(r.Key, r.Value, metadata, expiry); err != nil {
return errors.Wrap(err, "Couldn't insert record "+r.Key)
}