go - What does piece of code do in golang? -
this question has answer here:
- is casting in golang? 1 answer
i tried search , figure out how work i'm having trouble finding explanation.
if have variable data
of type interface{}
(data interface{}
)
what eventdata := data.(map[string]interface{})
doing? know interface can represent number of things, high level overview of happening here?
it type assertion:
a type assertion provides access interface value's underlying concrete value.
t := i.(t)
https://tour.golang.org/methods/15
if asserion not hold trigger panic. test if value of specific type t can use this:
t, ok := i.(t)
ok boolean true
if assertion holds , false
otherwise.
Comments
Post a Comment