Answer the question
In order to leave comments, you need to log in
How to access a structure field through a variable?
Hello everyone
Who knows how to refer to the structure field through a variable?
example:
type Example struct {
field1 string
field2 string
}
func main {
myStruct := Example{field1: "test1", field2: "test1"}
custom_field := "field1"
fmt.Println(myStruct.custom_field)
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question