Skip to content

Instantly share code, notes, and snippets.

@Kairi
Created September 16, 2014 06:42
Show Gist options
  • Select an option

  • Save Kairi/a187717a29621ac9d913 to your computer and use it in GitHub Desktop.

Select an option

Save Kairi/a187717a29621ac9d913 to your computer and use it in GitHub Desktop.
type assertion and switch
package main
import (
"fmt"
)
func typeCheck(value interface{}) {
switch t := value.(type) {
case string:
fmt.Println(t , "is string")
case int:
fmt.Println(t, "is int")
}
}
func main() {
typeCheck("Hello World")
typeCheck(123)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment