EUGENIO SOUZA CARVALHO 4 년 전
부모
커밋
8f76684761
1개의 변경된 파일36개의 추가작업 그리고 24개의 파일을 삭제
  1. 36 24
      api/mongo.go

+ 36 - 24
api/mongo.go

@@ -248,8 +248,9 @@ func (t *Mongo) Dispatch(f *Filter) {
 
 func (t *Mongo) InsertOne(f *Filter) (res *mongo.InsertOneResult, err *errs.Error) {
 	defer func() {
-		event := createDebugEvent(f, "models.insert.one")
-		event.Error = err
+		createDebugEvent(f, "models.insert.one", func(event *DebugEvent) {
+			event.Error = err
+		})
 	}()
 	f.Insertion = InsertOne
 
@@ -268,8 +269,9 @@ func (t *Mongo) InsertOne(f *Filter) (res *mongo.InsertOneResult, err *errs.Erro
 
 func (t *Mongo) InsertMany(f *Filter) (res *mongo.InsertManyResult, err *errs.Error) {
 	defer func() {
-		event := createDebugEvent(f, "models.insert.many")
-		event.Error = err
+		createDebugEvent(f, "models.insert.many", func(event *DebugEvent) {
+			event.Error = err
+		})
 	}()
 
 	f.Insertion = InsertMany
@@ -295,8 +297,9 @@ func (t *Mongo) InsertMany(f *Filter) (res *mongo.InsertManyResult, err *errs.Er
 //Remove os elementos da colecao, selecionados pela query
 func (t *Mongo) RemoveOne(f *Filter) (res *mongo.DeleteResult, err *errs.Error) {
 	defer func() {
-		event := createDebugEvent(f, "models.remove.one")
-		event.Error = err
+		createDebugEvent(f, "models.remove.one", func(event *DebugEvent) {
+			event.Error = err
+		})
 	}()
 
 	f.CheckQuery = true
@@ -323,8 +326,9 @@ func (t *Mongo) RemoveMany(f *Filter) (res *mongo.DeleteResult, err *errs.Error)
 	var lerr error
 
 	defer func() {
-		event := createDebugEvent(f, "models.remove.many")
-		event.Error = err
+		createDebugEvent(f, "models.remove.many", func(event *DebugEvent) {
+			event.Error = err
+		})
 	}()
 
 	f.CheckQuery = true
@@ -349,8 +353,9 @@ func (t *Mongo) UpdateOne(f *Filter) (res *mongo.UpdateResult, err *errs.Error)
 	var lerr error
 
 	defer func() {
-		event := createDebugEvent(f, "models.update.one")
-		event.Error = err
+		createDebugEvent(f, "models.update.one", func(event *DebugEvent) {
+			event.Error = err
+		})
 	}()
 
 	f.Insertion = InsertOne
@@ -380,8 +385,9 @@ func (t *Mongo) UpdateMany(f *Filter) (res *mongo.UpdateResult, err *errs.Error)
 	)
 
 	defer func() {
-		event := createDebugEvent(f, "models.update.many")
-		event.Error = err
+		createDebugEvent(f, "models.update.many", func(event *DebugEvent) {
+			event.Error = err
+		})
 	}()
 
 	f.Insertion = InsertMany
@@ -475,8 +481,9 @@ func ParseQuery(ctx iriscontext.Context, filter *Filter, basequery string, data
 
 func (t *Mongo) PatchOne(f *Filter) (res *mongo.UpdateResult, err *errs.Error) {
 	defer func() {
-		event := createDebugEvent(f, "models.patch.one")
-		event.Error = err
+		createDebugEvent(f, "models.patch.one", func(event *DebugEvent) {
+			event.Error = err
+		})
 	}()
 	f.Insertion = Patch
 	f.CheckQuery = true
@@ -548,8 +555,9 @@ func (t *Mongo) PatchOne(f *Filter) (res *mongo.UpdateResult, err *errs.Error) {
 
 func (t *Mongo) PatchMany(f *Filter) (res *mongo.UpdateResult, err *errs.Error) {
 	defer func() {
-		event := createDebugEvent(f, "models.patch.many")
-		event.Error = err
+		createDebugEvent(f, "models.patch.many", func(event *DebugEvent) {
+			event.Error = err
+		})
 	}()
 
 	f.Insertion = Patch
@@ -639,8 +647,9 @@ func (mongo *Mongo) FindOneRx(options *Filter) *ObservableStruct {
 
 func (t *Mongo) FindOne(f *Filter) (res *mongo.SingleResult, err *errs.Error) {
 	defer func() {
-		event := createDebugEvent(f, "models.find.one")
-		event.Error = err
+		createDebugEvent(f, "models.find.one", func(event *DebugEvent) {
+			event.Error = err
+		})
 	}()
 
 	f.CheckQuery = (f.QueryType != "aggregate")
@@ -692,8 +701,9 @@ func (t *Mongo) FindMany(f *Filter) (cursor *mongo.Cursor, err *errs.Error) {
 
 	// f.CheckQuery = true
 	defer func() {
-		event := createDebugEvent(f, "models.find.many")
-		event.Error = err
+		createDebugEvent(f, "models.find.many", func(event *DebugEvent) {
+			event.Error = err
+		})
 	}()
 
 	t.exec(f, func(ctx context.Context, collection *mongo.Collection) {
@@ -790,20 +800,22 @@ func (t *Mongo) FindMany(f *Filter) (cursor *mongo.Cursor, err *errs.Error) {
 	return
 }
 
-func createDebugEvent(options *Filter, eventType string) *DebugEvent {
+func createDebugEvent(options *Filter, eventType string, fn func(event *DebugEvent)) *DebugEvent {
 	// debug := options.Context.Values().Get("#debug")
 	debug := options.Context.Values().Get("#debug").(*DebugTaks)
 	event := debug.Event(eventType, "")
 	event.Data = iris.Map{}
+	fn(event)
 	return event
 }
 
 func (models *Mongo) Exists(options *Filter) (exists bool, err *errs.Error) {
 
 	defer func() {
-		event := createDebugEvent(options, "models.exists")
-		event.Data = iris.Map{"response": exists}
-		event.Error = err
+		createDebugEvent(options, "models.exists", func(event *DebugEvent) {
+			event.Data = iris.Map{"response": exists}
+			event.Error = err
+		})
 	}()
 
 	options.Fields = &bson.M{"_id": 1}