Let the protection key restate itself

This commit is contained in:
2020-11-18 22:32:00 +01:00
parent fc2a867cbb
commit c1ad7aea7d
4 changed files with 11 additions and 7 deletions
+8
View File
@@ -1,6 +1,8 @@
package protection
import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
@@ -9,3 +11,9 @@ type Key struct {
X primitive.ObjectID `bson:"_x" json:"_x" index:",hashed"`
V int64 `bson:"_v" json:"_v"`
}
// Restate creates a new protection key
func (k *Key) Restate() {
k.X = primitive.NewObjectID()
k.V = time.Now().Unix()
}
+1 -3
View File
@@ -2,7 +2,6 @@ package database
import (
"fmt"
"time"
"github.com/modern-go/reflect2"
"go.mongodb.org/mongo-driver/bson/primitive"
@@ -33,8 +32,7 @@ func (d *Database) DeleteOne(target interface{}, filters ...interface{}) (err er
if protected != nil {
query.Push(composed, protected)
protected.X = primitive.NewObjectID()
protected.V = time.Now().Unix()
protected.Restate()
}
defer func() {
+1 -4
View File
@@ -1,8 +1,6 @@
package database
import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
@@ -31,8 +29,7 @@ func (d *Database) SaveOne(source interface{}, filters ...interface{}) (err erro
if protected != nil {
query.Push(composed, protected)
protected.X = primitive.NewObjectID()
protected.V = time.Now().Unix()
protected.Restate()
}
defer func() {
+1
View File
@@ -38,6 +38,7 @@ func (d *Database) UpdateOne(target interface{}, filters ...interface{}) (err er
// "_v": time.Now().Unix(),
// },
//})
protected.Restate()
}
defer func() {