map we can do such:
value, present := m["key"]
or
value := m["key"]
and type assertion
var i interface{} = "hello"
s := i.(string)
fmt.Println(s)
s, ok := i.(string)
fmt.Println(s, ok)
but I can't find a way to define a func that can return 1 value or 2-value. for instance:
func hello() (string, error) {
return "world", nil
}
when invoke the func:
v, ok := hello() // valid
v := hello() // invalid
PS: I know something like template.Must
but it seems different, I really want to know how Map and type assertion can do the magic.
Thanks in advance. (am I clear? poor English sorry.