mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-05-22 15:53:36 +00:00
Make package for protection struct
This commit is contained in:
@@ -2,10 +2,12 @@ package base
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/mainnika/mongox-go-driver/v2/mongox/base/protection"
|
||||
)
|
||||
|
||||
// GetProtection function finds protection field in the source document otherwise returns nil
|
||||
func GetProtection(source interface{}) *Protection {
|
||||
func GetProtection(source interface{}) *protection.Key {
|
||||
|
||||
v := reflect.ValueOf(source)
|
||||
if v.Kind() != reflect.Ptr || v.IsNil() {
|
||||
@@ -19,11 +21,11 @@ func GetProtection(source interface{}) *Protection {
|
||||
field := el.Field(i)
|
||||
|
||||
switch field.Interface().(type) {
|
||||
case *Protection:
|
||||
return field.Interface().(*Protection)
|
||||
case Protection:
|
||||
case *protection.Key:
|
||||
return field.Interface().(*protection.Key)
|
||||
case protection.Key:
|
||||
ptr := field.Addr()
|
||||
return ptr.Interface().(*Protection)
|
||||
return ptr.Interface().(*protection.Key)
|
||||
default:
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package base
|
||||
package protection
|
||||
|
||||
import (
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// Protection field stores unique document id and version
|
||||
type Protection struct {
|
||||
// Key field stores unique document id and version
|
||||
type Key struct {
|
||||
X primitive.ObjectID `bson:"_x" json:"_x" index:",hashed"`
|
||||
V int64 `bson:"_v" json:"_v"`
|
||||
}
|
||||
Reference in New Issue
Block a user