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

在Go中初始化结构

Is this valid syntax for initializing a struct in Go?

id := struct { name, ltype, value }

The fields are all strings. The actual error message I get is "syntax error: unexpected }". Maybe you cant initialize anonymous structs this way ?

No type inference for you!

name := "a"
ltype := "b"
value := "c"
id := struct { name, ltype, value string } { name, ltype, value }

You can also initialize the value inline.

id := struct{ name, ltype, value string }{"a", "b", "c"}

近期文章

  • 不要使用GoClipse制作二进制文件
  • Go中奇怪的编译器错误
  • Go-系统时间以皮秒为单位
  • 从精读的HTTP中解组JSON:无效字符寻找值的开头
  • 从Python移植到Go的算法
  • Go工具封面的HTML输出:每个文件的覆盖率概述
  • 是否有可能突破受限(自定义)外壳?
  • 用于在go中获取不同属性的泛型函数
  • 在App Engine上的Go中为N到N关联建模
  • 如果结构A嵌入在B中,则A上的方法可以访问B的方法吗?
  • 有什么方法可以检查Go chan中是否缓冲了值?
  • 如何从此请求获取POST值?
  • 函数自动执行而不被调用
  • Go中恒定的全局用户类型值
  • 如何检查值是否实现接口
  • 时间格式转换为strftime默认格式
  • 进行结构比较-reflect.DeepEqual在地图上失败吗?
  • 您是否需要使用互斥锁来锁定const?
  • 此代码使用变量“ ok”,但未定义
  • Golang检查数据是否是时间

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华