Skip to content

Instantly share code, notes, and snippets.

@lamarmarshall
Last active October 26, 2017 23:47
Show Gist options
  • Save lamarmarshall/29eafe3a6240ace93a39ae3509aa7839 to your computer and use it in GitHub Desktop.
Save lamarmarshall/29eafe3a6240ace93a39ae3509aa7839 to your computer and use it in GitHub Desktop.
generic function arguments, interface arguments
package main
import (
"fmt"
)
func whatami(tp interface{}) {
switch tp.(type) {
case int:
fmt.Println("i am an int")
case string:
fmt.Println("i am a string")
}
/* capture the value
switch val := tp.(type) {
case int:
fmt.Println("i am an int", val)
case string:
fmt.Println("i am a string", val)
}
*/
}
func main() {
whatami(25)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment