Let the protection key restate itself

v2
Nikita Tokarchuk 4 years ago
parent fc2a867cbb
commit c1ad7aea7d
No known key found for this signature in database
GPG Key ID: DBFD964471BAE65C
  1. 8
      mongox/base/protection/key.go
  2. 4
      mongox/database/deleteone.go
  3. 5
      mongox/database/saveone.go
  4. 1
      mongox/database/updateone.go

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

@ -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,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() {

@ -38,6 +38,7 @@ func (d *Database) UpdateOne(target interface{}, filters ...interface{}) (err er
// "_v": time.Now().Unix(),
// },
//})
protected.Restate()
}
defer func() {

Loading…
Cancel
Save