cast icon indicating copy to clipboard operation
cast copied to clipboard

Add ability to supply conversion type as string arg

Open blacktop opened this issue 3 years ago • 1 comments

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)
     }
}   

blacktop avatar Aug 15 '22 02:08 blacktop

So type has to be a valid Go type and value will be any

blacktop avatar Aug 15 '22 02:08 blacktop