如何在Go Lang Fabric链码中访问数组元素?

I had created a basic structure,

type UpdateRequest struct {
    UrID                string  `json:"urID"`
    Ssn                 string  `json:"ssn"`
    ReqType             string  `json:"reqType"`
    ReqValue            string  `json:"reqValue"`
    CreatedAt           string  `json:"createdAt"`
    LastModifiedAt      string  `json:"lastModifiedAt`
    ActionTakenAt       string  `json:"actionTakenAt`
    ReqStatus           string  `json:"reqStatus"`
}

For accessing each records for the above structure I created a function named as getFieldString which reads each fields from a structure individually

func getFieldString(e *Employee, field string) string  {
       r := reflect.ValueOf(e)
       f := reflect.Indirect(r).FieldByName(field)
       return f.String()  }

So If i want to access Urid from the above structure I can just use

var ur UpdateRequest;
getFieldString(&ur,"Urid")

I have declared a new structure which has a String array.

 type SSNList struct{ SSNArray []string }

I am having trouble retrieving the array object stored in a structure. Is there any other way instead of using Reflect and Indirect?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问