title: Go - How can I check for type equality?
body: <p>Say I have the following code:</p>
  
  <pre><code>var x interface{}
  y := 4
  x = y
  fmt.Println(reflect.TypeOf(x))
  </code></pre>
  
  <p>This will print int as the type. My question is how can I test for the type? I know there is the type switch which does this, so I could do:</p>
  
  <pre><code>switch x.(type) {
  case int:
      fmt.Println("This is an int")
  }
  </code></pre>
  
  <p>But if I only want to check for just one specific type the switch seems like the wrong tool. Is there a more direct method of doing this like</p>
  
  <pre><code>reflect.TypeOf(x) == int
  </code></pre>
  
  <p>or is the type switch the way to go?</p>