lundi 8 août 2022

Iterate over the field of structs and modify the value [duplicate]

I am new to golang, but here is my structure:

type CellMetricsEntry struct {
    DRBUEThpDl             interface{}
    DRBUEThpUl             interface{}
    QosFlowPdcpPduVolumeUl interface{}
    QosFlowPdcpPduVolumeDl interface{}
}

In the above structure there are more than 100 variables, but here I have taken only 4.

in main function I somehow want to iterate over the field and want to modify it, as per my need.

The field values can either be an int32 or float64

How can i iterate over this structure field and modify the value.

I want to achieve something like

var metric CellMetricsEntry

for (int i=0;i< no_of_elements;i++)//this is pseudo code
{
metric[i]=value//setting  each field of struct in for loop
//the above value I will get from some other application and this may be //either int32 or float64


}

After setting all the field , I will push it to Time series database like influxdb

writecellMetrics_db(metric)




Aucun commentaire:

Enregistrer un commentaire