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) *Struct

Parameters & Attributes

NameTypeDescription
fields[]*VarField variables in declaration order.
tags[]stringOptional 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"}))}
Go Reference