Standard library / go/types
go/types.NewStruct()
Constructs a struct type descriptor. This does not allocate a runtime value. Expected stdout: 'struct{X int "json:x"}\n'.
Formal Syntax & Structure
go syntaxgo
func NewStruct(fields []*Var, tags []string) *StructParameters & Attributes
| Name | Type | Description |
|---|---|---|
| fields | []*Var | Field variables in declaration order. |
| tags | []string | Optional field tags in declaration order. |
Return Value
*Struct
Constructs a struct type descriptor.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func main() { fmt.Println(types.NewStruct([]*types.Var{types.NewField(0, nil, "X", types.Typ[types.Int], false)}, []string{"json:x"}))}