Arquivo da categoria: Go

Golang – Print de struct

https://play.golang.org/p/zSJ6DuM1fOm

package main

import (
“fmt”
“reflect”
)

func main() {
type T struct {
Armando int
Gay string
}

t := T{23, "skidoo"}
s := reflect.ValueOf(&t).Elem()
typeOfT := s.Type()

for i := 0; i < s.NumField(); i++ {
    f := s.Field(i)
    fmt.Printf("%d: %s %s = %v\n", i,
        typeOfT.Field(i).Name, f.Type(), f.Interface())
}

}