Ai
1 Star 0 Fork 0

mosache/go-zero

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 660 Bytes
一键复制 编辑 原始数据 按行查看 历史
kevwan 提交于 2020-10-16 10:50 +08:00 . fix golint issues
package main
import (
"log"
"strconv"
"github.com/tal-tech/go-zero/core/mr"
)
type User struct {
Uid int
Name string
}
func main() {
uids := []int{111, 222, 333}
res, err := mr.MapReduce(func(source chan<- interface{}) {
for _, uid := range uids {
source <- uid
}
}, func(item interface{}, writer mr.Writer, cancel func(error)) {
uid := item.(int)
user := &User{
Uid: uid,
Name: strconv.Itoa(uid),
}
writer.Write(user)
}, func(pipe <-chan interface{}, writer mr.Writer, cancel func(error)) {
// missing writer.Write(...), should not panic
})
if err != nil {
log.Print(err)
return
}
log.Print(len(res.([]*User)))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mosache/go-zero.git
git@gitee.com:mosache/go-zero.git
mosache
go-zero
go-zero
dfb45c801a6c

搜索帮助