Exercises & activities from the go workshop provided by Packt: https://courses.packtpub.com/courses/go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

29 lines
444 B

package main
import (
"errors"
"fmt"
)
func doubler(v interface{}) (string, error) {
if i, ok := v.(int); ok {
return fmt.Sprint(i * 2), nil
}
if s, ok := v.(string); ok {
return s + s, nil
}
return "", errors.New("unsupported type passed")
}
func main() {
res, _ := doubler(5)
fmt.Println("5 :", res)
res, _ = doubler("yum")
fmt.Println("yum:", res)
_, err := doubler(true)
fmt.Println("true:", err)
}