Standard library / reflect

reflect.StructField

Metadata for a struct field, including name, type, tag, byte offset and index path. An embedded field’s offset is relative to its immediate containing struct. Expected stdout: 'ID id\n'.

Formal Syntax & Structure

go syntaxgo
type StructField struct {  Name string
  PkgPath string
  Type      Type  Tag       StructTag  Offset    uintptr  Index     []int  Anonymous bool}

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() {  type Row struct {    ID int `json:"id"`  }  f := reflect.TypeOf(Row{}).Field(0)  fmt.Println(f.Name, f.Tag.Get("json"))}
Go Reference