golang 返回值报错 cannot use nil as type string in return argument
在刚刚开始使用golang写代码的时候,经常会放错。给一个变量放回一个nil,这个通常编译的时候不会报错,但是运行是时候会报cannot use nil as type string in return argument的错误,对于nil,一般通常指针类型和interface类型可以使用这样的返回值
错误示例如下:
func Get(m map[int]string, id int) (string, bool) {if _, exist := m[id]; exist {return "存在数据", true}return nil, false
}
正确示例如下:
func Get(m map[int]string, id int) (string, bool) {if _, exist := m[id]; exist {return "存在数据", true}return "", false
}
golang 返回值报错 cannot use nil as type string in return argument相关推荐
- falsk 请求没有返回值报错
线上报警 5xx 错误,查看日志发现报这个错, TypeError: The view function did not return a valid response. The function e ...
- {__ob__: observer}取值报错问题
{ob: observer}取值报错问题 解决方案:JSON.parse(JSON.stringify( ob )) 在直接对{ob: observer}访问属性时会报错,网上看到的大多数人是报und ...
- 使用golang发送邮件,报错“x509: certificate signed by unknown authority”
问题描述 使用golang发送邮件,报错"x509: certificate signed by unknown authority",这是由于客户端默认要对服务端传过来的数字证书 ...
- Java IDEA pom 报错java.lang.OutOfMemoryError: GC overhead limit exceeded 基本所有依赖都报错(除了JDK自带String等)解决详
@Java IDEA pom 报错java.lang.OutOfMemoryError: GC overhead limit exceeded 基本所有依赖都报错(除了JDK自带String等)解决详 ...
- 关于Swagger报错java.lang.NumberFormatException: For input string: 的总结
关于Swagger报错java.lang.NumberFormatException: For input string: ""的总结 1 为什么会报错? 2 如何排错? 3 哪种 ...
- 安装 sklearn 报错 ImportError: cannot import name Type
1. 安装 sklearn sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple sklearn 会默认安装 joblib , s ...
- SAP SD VL02N对STO的交货单执行PGI,报错 -Fld selectn for mvmt type 643 acct 400020 differs for Business Area –
SAP SD VL02N对STO的交货单执行PGI,报错 -Fld selectn for mvmt type 643 acct 400020 differs for Business Area – ...
- SAP VLPOD 报错 - Update control of movement type is incorrect (entry 107 X X E B _ E) - 之对策
SAP VLPOD 报错 - Update control of movement type is incorrect (entry 107 X X E B _ E) - 之对策 如下的DN 8002 ...
- SAP WM 自动创建TO单的JOB运行报错 - Enter the storage unit type - 对策
SAP WM 自动创建TO单的JOB运行报错 - Enter the storage unit type - 对策 报错如下: 详细信息: Log for automatic creation of ...
最新文章
- (操作系统)实验二 作业调度
- python中函数的调用_慢步python,编程中函数的概念,python中函数的声明和调用
- java系列5:如何使用创建的类
- 佳士得于5月19日至27日以NFT形式拍卖安迪·沃霍尔作品
- Vue组件相关的知识
- Mac文件夹图标颜色自定义工具Color Folder
- git如何选择性合并_看小姐姐用动图展示10大Git命令
- 怎样快速的学习微信小程序
- 如何固定电脑桌面便签 win7便签怎么设置?
- ORACLE数据恢复到指定时间
- thinkpkp typecho maccms 全站加密不改动源码方法,多数php程序通用
- docker的搭建和简单应用
- PS:换背景天空(简单抠图)
- 念整数(你的程序要读入一个整数,范围是[-100000,100000]。然后,用汉语拼音将这个整数的每一位输出出来。 如输入1234,则输出: yi er san si)
- Github使用秘籍
- 2021湖南涟源高考成绩查询,2021娄底市地区高考成绩排名查询,娄底市高考各高中成绩喜报榜单...
- Barrier多计算机共享键鼠详细教程(可跨平台)+使用感受
- 多因子选股模型 —— 因子间相关性检验和等权因子法
- 电赛综合测评题练习(一)-(与2013年电赛综合测评要求类似)
- oracle修改数据文件名称
热门文章
- 用 Flask 来写个轻博客 (29) — 使用 Flask-Admin 实现后台管理 SQLAlchemy
- Arduino方式开发ESP32笔记:使用Preferences保存数据
- j-link接口定义及实际使用
- u32和字符串的转换函数
- Java vs Big data 哪种编程语言更好?
- 第五个页面:更多电影页面
- 【Azure Services Platform Step by Step-第14篇】使用Azure版的ASP.NET Application Providers
- 移动端 元素外面使用伪类after加边框 导致其内部元素无法选中
- J2SE的30个基本概念
- 菜鸟学习计划浅谈之Linux系统