Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
在使用时发现 casToken 存在问题:casToken 是私有结构体,意味着包外部的代码无法引用它,这一设计是有意为之的,因为理论上 casToken 只能由本包内生成且只在本包内使用,外部没有创建 casToken 的需求所以就没有把 casToken 结构体公开出去。然而在实际工程实践中,发现 casToken 经常会出现在函数形参中,参考业务中的一个方法
如果此时没有公开的 CasToken 结构体,那该方法就必须写成
其中
mr
是上一次查询返回的 metaResult,这种写法传入了过多该函数职责之外的信息,不利于业务代码维护。使用 interface 可以实现既保持 casToken 的收敛,又可被外部代码引用作为形参提升工程效率。
同时由于引入了 interface,其实参存在 nil 状态,于是便可区分为空和零值的情况,原先的 casToken 结构体也就不在必要,直接改为 int64 类型。