I am having a function like this:
package main
import "flag"
import "fmt"
func print_out_type(x anything) string {
switch v := x.(type) {
case string:
return "A string"
case int32:
return "An Integer"
default:
return "A default"
}
}
func main() {
wordPtr := flag.String("argument1", "foo", "a String")
numPtr := flag.Int("argument2", 42, "an Integer")
flag.Parse()
fmt.Println("word: ", *wordPtr)
fmt.Println("number: ", *numPtr)
}
I am trying to return different types of strings based on the type. I am just stuck at the point of how do I write a function that accepts arguments of different types.