-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutator.go
36 lines (29 loc) · 842 Bytes
/
mutator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package mttor
import (
"context"
"reflect"
"github.com/teawithsand/reval/stdesc"
"go.mongodb.org/mongo-driver/bson"
)
type MutatorData struct {
Value interface{}
Args MutationArgs
FieldName string
MutationName string
}
// Mutator is part of DefaultMutator, which applies mutation using data it's given.
type Mutator interface {
ApplyMutation(ctx context.Context, target reflect.Value, field stdesc.Field, data MutatorData) (err error)
}
type MongoMutatorData struct {
MutatorData
BSONFieldName string
Skip bool
}
// Mutation, which is able to render itself as mongodb mutation.
type MongoMutator interface {
Mutator
// Returns mongo mutation name, so appropriate bson.D can be passed.
MongoMutationName() string
RenderMongoDoc(ctx context.Context, data MongoMutatorData) (entry bson.E, err error)
}