Skip to content

Rename the second parameter of middleware.Do  #242

Closed

Description

@zhengyuchuan

Describe the bug
Query对象的One方法和All方法中,执行middleware.Do时,将hook传给了doc

func (q *Query) One(result interface{}) error {
if len(q.opts) > 0 {
// 这里
if err := middleware.Do(q.ctx, q.opts[0].QueryHook, operator.BeforeQuery); err != nil {
return err
}
}
opt := options.FindOne()

if q.sort != nil {
	opt.SetSort(q.sort)
}
if q.project != nil {
	opt.SetProjection(q.project)
}
if q.skip != nil {
	opt.SetSkip(*q.skip)
}
if q.hint != nil {
	opt.SetHint(q.hint)
}

err := q.collection.FindOne(q.ctx, q.filter, opt).Decode(result)

if err != nil {
	return err
}
if len(q.opts) > 0 {
             // 还有这里
	if err := middleware.Do(q.ctx, q.opts[0].QueryHook, operator.AfterQuery); err != nil {
		return err
	}
}
return nil

}

Activity

  1. zhengyuchuan commented on May 2, 2022

    @zhengyuchuan
    Author

    hook这里感觉写的不好啊

  2. jiangz222 commented on Oct 4, 2022

    @jiangz222
    Collaborator

    We can make the naming of the second parameter of middleware.Do more accurate, but I think there is no bug!

  3. changed the title [-]Query中middleware bug[/-] [+]Rename the second parameter of middleware.Do [/+] on Oct 4, 2022
  4. added a commit that references this issue on Oct 4, 2022
    9b75989
  5. added a commit that references this issue on Oct 31, 2024
    d076e1b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址