Go泛型设计又有新变化 | Gopher Daily (2021.04.02) ʕ◔ϖ◔ʔ

每日一谚:Lack of hidden control flow (throw/try/catch/finally) improves readability.

Go技术生态

  1. spaghetti:基于Web的交互式的Go包依赖分析工具 - https://github.com/adonovan/spaghetti

  2. Go原生支持fuzz test的提案被accept - https://github.com/golang/go/issues/44551

  3. 用于Go语言开发的Top 10 IDE和工具 - https://www.mindinventory.com/blog/golang-ide-tools-for-go-development/

  4. 使用Promtail, Loki, Grafana搭建k8s日志分析系统 - https://itnext.io/logging-in-kubernetes-with-loki-and-the-plg-stack-93b27c90ec34

  5. google开源的与容器镜像仓库交互的go包与命令行工具 - https://github.com/google/go-containerregistry

  6. go tip版本已经实现基于寄存器的ABI规范(以前是基于栈的) - https://github.com/golang/go/issues/40724#issuecomment-811561715

  7. Go 1.16.3和Go 1.15.11 发布 - https://groups.google.com/g/golang-announce/c/wVRzkWSQpO0/m/EUykHAm0CAAJ

  8. Go设计草案:Go漏洞数据库 - https://go.googlesource.com/proposal/+/master/design/draft-vulndb.md

  9. 使用Go和kotlin重写alda - https://blog.djy.io/why-im-rewriting-alda-in-go-and-kotlin/

  10. 云提供商的CPU基准测试 - https://thenewstack.io/cpu-benchmarks-for-cloud-providers-intel-vs-amd-vs-amazons-arm-based-graviton2/

  11. Go泛型设计又有新简化:约束中的type关键字被去掉 - https://github.com/golang/go/issues/45346

Go技术进阶专栏导读

Go 原生在工具链和标准库中提供对测试的支持。但很多初学者可能会困惑于测试包究竟是使用与目标包同名的包名还是使用xx_test作为包名?Go进阶专栏“改善Go语⾔编程质量的50个有效实践”的第33篇文章《一文告诉你测试包的包名要不要带“_test”后缀》 https://www.imooc.com/read/87/article/2436 将为你答疑解惑!

资料下载

关注公众号iamtonybai,发送特定关键字获取对应精品资料!

  • Go语言学习技术路线图2021版 - 发送go2021

  • GopherChina 2020技术大会ppt资料 - 发送gopherchina2020

  • GopherCon 2020大会技术ppt资料 - 发送gophercon2020

  • 《设计数据密集型应用程序》作者Martin Kleppmann新课“分布式系统”的讲义资料 - 发送distsys

  • O'Reilly的《分布式跟踪实战(Distributed Tracing in Practice)》 - 发送distrace

  • 加州伯克利的47页的“机器学习的数学基础”资料 - 发送math4ml

“Gopher部落”,新年新气象

“Gopher部落”正式转正(从试运营星球变成了正式星球)!“gopher部落”旨在打造一个精品Go学习和进阶社群,目前虽小,但持续力很强。在2021年上半年,部落将策划两个专题系列分享,并且是部落独享哦:

  • Go技术书籍的书摘和读书体会系列

  • Go与eBPF系列

感谢大家对本星球的支持!

联系方式

  • 有意想学习容器或Kubernets的童鞋可以了解一下我的慕课网实战课:k8s实战 - https://coding.imooc.com/class/284.html

  • gopherdaily归档:https://github.com/bigwhite/gopherdaily

  • 编辑:Tony Bai (https://tonybai.com)

  • 邮件订阅:https://gopher-daily.com/

  • 知乎Go进阶专栏:https://www.zhihu.com/column/c_1352639051791454208

  • “Gopher部落”知识星球:https://public.zsxq.com/groups/51284458844544

  • 微信公众号:iamtonybai

往期推荐

Go语言中常见的几种反模式[译]

Go语言的“黑暗角落”:盘点学习Go语言时遇到的那些陷阱

使用Go实现可用select监听的队列

Go 1.16版本正式发布

基于Redis Cluster的分布式锁实现以互斥方式操作共享资源

Go语言学习技术路线图2021发布了!

以单件方式创建和获取数据库实例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
感谢指出错误。警告是由于在返回的 JSON中,节点数据以字典的形式存在,而不是元组。这可以通过将查询结果转换为字典形式来解决。 以下是修改后的代码示例: ```python @app.route('/api/get_data', methods=['GET', 'POST']) def get_data(): keyword = request.args.get('keyword') # 获取请求参数 keyword cursor = mysql.cursor() # 根据关键字查询nodes表的数据 if keyword: cursor.execute("SELECT * FROM nodes WHERE type=%s", (keyword,)) nodes_data = cursor.fetchall() else: cursor.execute("SELECT * FROM nodes") nodes_data = cursor.fetchall() # 获取节点的ID列表 node_ids = [row[0] for row in nodes_data] edges_set = set() # 使用集合存储边数据,确保每条边只出现一次 # 根据节点的ID查询相关的边数据 for node_id in node_ids: cursor.execute("SELECT * FROM edges WHERE `from_id`=%s or `to_id`=%s", (node_id, node_id)) edges_data = cursor.fetchall() for row in edges_data: edge = { 'from': row[0], 'to': row[1], 'label': row[2], 'arrows': row[3] } edges_set.add((edge['from'], edge['to'], edge['label'], edge['arrows'])) # 将边数据添加到集合中 # 补全缺少的节点信息 if keyword: existing_node_ids = set(node_ids) # 存储已有节点的ID for node_id in node_ids: if node_id not in existing_node_ids: cursor.execute("SELECT * FROM nodes WHERE id=%s", (node_id,)) node_data = cursor.fetchone() if node_data: node = { 'id': node_data[0], 'type': node_data[1], 'label': node_data[2] } nodes_data.append(node) existing_node_ids.add(node_id) cursor.close() return jsonify({'nodes': nodes_data, 'edges': list(edges_set)}) ``` 现在,返回的 JSON 数据中的节点数据应该是以字典形式存在,而不再产生警告。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值