I have not found a good resource for using interface{}
types. For example
package main
import \"fmt\"
func weirdFunc(i int) interface{} {
Your example does work. Here's a simplified version.
package main
import "fmt"
func weird(i int) interface{} {
if i < 0 {
return "negative"
}
return i
}
func main() {
var i = 42
if w, ok := weird(7).(int); ok {
i += w
}
if w, ok := weird(-100).(int); ok {
i += w
}
fmt.Println("i =", i)
}
Output:
i = 49
It uses Type assertions.