We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
beyond/application/article/rpc/internal/logic/articleslogic.go 里面的cmp包以及 slices 是哪来的?
The text was updated successfully, but these errors were encountered:
后面加的,使用mapreduce获取文章列表是无序的,因为返回的文章是需要排序,所以使用了slices.SortFunc对获取的文章进行排序,排序的方法有很多种,你也可以使用其他的排序方法 关于这个部分的改动可以查看这个#23
slices.SortFunc
Sorry, something went wrong.
slices.SortFunc 是 go 1.21版本增加的方法, 相关连接 Go 1.21 Release Notes 旧版本可使用以下实现切片排序
var cmpFunc func(i, j int) bool if sortField == "like_num" { cmpFunc = func(i, j int) bool { return articles[i].LikeNum > articles[j].LikeNum } } else { cmpFunc = func(i, j int) bool { return articles[i].PublishTime.Unix() > articles[j].PublishTime.Unix() } } sort.Slice(articles, cmpFunc)
No branches or pull requests
beyond/application/article/rpc/internal/logic/articleslogic.go
里面的cmp包以及 slices 是哪来的?
The text was updated successfully, but these errors were encountered: