cast
cast copied to clipboard
Add ability to supply conversion type as string arg
I'm using yaml to define Go structs so:
args:
- name: Field1
type: uint64
value: 32
- name: Field2
type: uint32
value: 200
type Field struct {
Name string
Type string
Value any
}
So when I unmarshal I want to write that struct to a []byte
So it'd be awesome if I could use cast to do:
for _, arg := range args {
for _, field := range arg {
val := cast.Convert(type, value)
binary.Write(r, binary.LittleEndian, &val)
}
}
So type has to be a valid Go type and value will be any