我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

Go中函数中返回变量的数量可变

I wonder if there is a way to implement a function that behaves similar to map getter: it returns return value as first argument and (optionally assigned) second value ok as second argument. So I need function f that I can call in following ways:

value1 := f(1)
value2, ok := f(2)

No, it can't be done, the only option is to return a pointer and check if it's nil.

if v := f(10); v != nil {
     //stuff
}

近期文章

  • Golang:/ usr / local / go / src / Make .:没有这样的文件或目录
  • 如何在Windows上构建Go-SDL?
  • GAE Go-如何处理ErrConcurrentTransaction数据存储区事务错误
  • SQL选择-返回的总行数
  • 转到:连接文件内容
  • myeclipse10里图形界面开发
  • 许多客户端连接到Go服务器时出错
  • 在Windows上安装:“访问被拒绝”
  • 转到:调用将指针传递给数组的函数
  • 转到Subversion的绑定[关闭]
  • 简单测试失败
  • 通过go和python进行gprc演示
  • 如何实现在固定长度的字节数组集中搜索前缀的有效方法?
  • Go App Engine-测试Memcache服务失败
  • HTTP NTLM身份验证
  • 使用Envoy进行GRPC负载平衡
  • Golang语法错误:写入文件时出现意外的EOF
  • 转到:带有指针的json编码结构比使用副本慢吗?
  • 在完成时将频道结果添加到队列的更惯用的方法
  • SQLboiler not in子句

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华