W
W
wanomgn2018-12-13 09:56:44
go
wanomgn, 2018-12-13 09:56:44

How to get value from interface?

Good afternoon.
the answer comes from the database in the form of an interface in which two fields
I want to separately receive only the second field

resp, err := conn.Select("bla bla bla")
fmt.Printf("%T\n", resp.Data)
fmt.Println(resp.Data)

at the output we get:
[]interface {}

how CORRECTLY to get only "sss" into a string variable?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pavlyuk, 2018-12-13
@pav5000

You receive not an interface of two fields, but a regular slice (array) of interfaces. Work with it like with any other slice.

fmt.Println(len(resp.Data))
fmt.Println(resp.Data[0])
fmt.Println(resp.Data[1])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question