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

Ruby或等于的golang版本|| =

Out of curiosity, what would be the idiomatic way to assign a variable if it's nil in go?

I'm looking for something similar to ruby's foo ||= bar

Is there a shorter version of this?

if foo == nil{  
  foo = bar
}

Your version is already the simplest, shortest and idiomatic way to do it.

近期文章

  • libgit2高山linux docker错误
  • 在切片上进行循环索引以获取范围
  • goroutine golang中的一个进程错误
  • 延迟关闭多个Goroutine?
  • 使用Golang mgo.v2的嵌套MongoDB查询
  • 返回自身的接口(可克隆)
  • Golang中的死锁错误
  • 使用Go将结构转换为[] byte
  • 在Go中,如何使用切片创建通用函数?
  • Golang:将结构转换为偏移量为0的结构
  • 如何减少golang中重复的http处理程序代码?
  • 如何从外部对golang http上传进行速率限制?
  • 如何确定转到通道的哪一侧正在等待?
  • 如何在GO中等待POST请求完成?
  • 为什么Go Map vs Slice性能在这里有10倍的速度差异
  • 什么规则决定Go软件包的安装位置?
  • 如何使用逗号连接领事模板的服务元数据
  • 如何确保NoSQL记录中的属性的唯一性(Golang + tiedot)
  • 我可以使用什么系统调用/方法来获取默认的网络网关
  • golang appengine api测试错误“ appengine:NewContext传递了未知的http.Request”

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华