Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scanner.Scan返回错误码 #119

Open
leaftree opened this issue Aug 27, 2021 · 3 comments
Open

scanner.Scan返回错误码 #119

leaftree opened this issue Aug 27, 2021 · 3 comments

Comments

@leaftree
Copy link

https://github.com/didi/gendry/blob/master/scanner/scanner.go#L94

如果scan不到数据,并且入参是slice,为什么返回错误码返回nil而不是返回ErrEmptyResult呢

@caibirdme
Copy link
Contributor

对于一个结构体,如果不返回错误,你无法知道查询结果真的就是各个field都是0值还是没查询到,所以需要返回一个ErrEmptyResult
对于slice,你判断len(target) > 0 就知道是否是empty了。

@leaftree
Copy link
Author

感谢你的回复!
对于target是slice的时候,如果我们能够只使用err这个条件来判断就好了。
期望在 len(target)==0 的时候Scan函数也返回ErrEmptyResult。

@andotorg
Copy link

这样不太合理,因为每个人的使用场景都不一样,你可以增加一个封装判断leng == 0 然后返回 ErrEmptyResult

感谢你的回复! 对于target是slice的时候,如果我们能够只使用err这个条件来判断就好了。 期望在 len(target)==0 的时候Scan函数也返回ErrEmptyResult。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants