- Check if a variable implements a given interface and obtain the variable in the context of that interface:
m, ok := val.(json.Marshaler)
-For example:
if _, ok := val.(json.Marshaler); ok {
fmt.Printf("value %v of type %T implements json.Marshaler\n", val, val)
}
No comments:
Post a Comment