lundi 22 février 2016

How to set array value to a field in golang using reflect?

I have a Struct with following fields

type Config struct {
        Address[]string
        Name string
}

I am reading the values for this Config from a file in JSON format

{
   "Address": ["xx.xx.xx.xx","xx.xx.xx.xx"],
   "Name":"Name"
}

I have used Reflect to identify the type and set its value to Config.I am able to set the value of Name field using func (v Value) SetString(x string) which is an inbuilt method in reflect. Is there a way to set []string values directly to a field? Please help.





Aucun commentaire:

Enregistrer un commentaire