Skip to content

Instantly share code, notes, and snippets.

@podhmo
Created January 18, 2023 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save podhmo/c9e5971100bee5d3a0ec16f77b6db684 to your computer and use it in GitHub Desktop.
Save podhmo/c9e5971100bee5d3a0ec16f77b6db684 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"reflect"
reflectshape "github.com/podhmo/reflect-shape"
)
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
}
func main() {
fmt.Println(reflect.TypeOf(Person{}))
fields := []reflect.StructField{
{
Name: "Name",
Type: reflect.TypeOf(""),
Tag: `json:"name"`,
},
{
Name: "Age",
Type: reflect.TypeOf(int(0)),
Tag: `json:"age"`,
},
}
rtype := reflect.StructOf(fields)
fmt.Println(rtype)
cfg := &reflectshape.Config{}
shape := cfg.Extract(reflect.New(rtype).Interface())
fmt.Println(shape)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment