Created
January 18, 2023 09:02
-
-
Save podhmo/c9e5971100bee5d3a0ec16f77b6db684 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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