mercredi 12 août 2020

Golang update nested structures [duplicate]

I have a nested struct , something like this

type InnerLevel1 struct {
    ValInnerLevel1 *InnerLevel2
}
type InnerLevel2 struct {
    ValInnerLevel2 big.Int
}
type Outer struct {
    ValOuter InnerLevel1
}

I want to write a function which can update one of the values if I pass the object path to it

ValOuter.ValInnerLevel1.ValInnerLevel2 = 100000000000000

I tried using json to convert the struct to a map ,but that does not work ,is there something else i should be looking at ?

I put the whole thing in a go playground as well https://play.golang.org/p/UCoYGsfywe3





Aucun commentaire:

Enregistrer un commentaire