空嵌套结构

Hay*_*yan 5 go

我正在挖掘AWS SDK源代码并遇到以下类型声明:

type Condition struct {
    _ struct{} `type:"structure"`

    // the rest of code is removed
}
Run Code Online (Sandbox Code Playgroud)

有人知道这种嵌入的目的/解释吗?

Cal*_*oki 1

它被用于代码生成。你可以把它想象成java,它将其中的所有内容都视为对象。

使用它的示例在这里

{{ $shapeList := ShapeListWithErrors $ }}
{{ range $_, $s := $shapeList }}
{{ if eq $s.Type "structure"}}{{ $s.GoCode }}{{ end }}
{{ end }}
Run Code Online (Sandbox Code Playgroud)