go - What does piece of code do in golang? -


this question has answer here:

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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -