Hello All,
I’m studying golang and wish some assist please.
i’ve a variable transformedEmail that appears like this when printed::
fmt.Printf("debug: %T, %v", transformedEmail, transformedEmail)
debug: []interface {}, [map[encoded_value:.YlGhCqAs@gmail.com] map[encoded_value:+61-442-291-954] map[encoded_value:9872-5721-5683-2126] map[encoded_value:830-726 79679125]]%
I need to loop via it and get the worth of every “encoded_value”, how might I do it?
Thanks
I’ve
I’ve tried to make use of transformedEmail[0] however I get following error:
invalid operation: can not index transformedEmail (variable of kind interface{})compilerNonIndexableOperand
Your transformedEmail
should have been declared as kind interface{}
. The %T let you know its dynamic kind is []interface{}
. Use a sort assertion to get the slice variable you can index.
transformedEmailSlice,okay := transformedEmail.([]interface{})
if !okay {
log.Fatalf("transformedEmail shouldn't be actually a []interface{}")
}
for i, aspect := vary transformedEmailSlice {
fmt.Printf("transformedEmail aspect %d: %T %vn",i,aspect,aspect)
}