title: How to compare if two structs, slices or maps are equal?
body: <p>I want to check if two structs, slices and maps are equal.</p>
  
  <p>But I'm running into problems with the following code. See my comments at the relevant lines.</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "reflect"
  )
  
  type T struct {
      X int
      Y string
      Z []int
      M map[string]int
  }
  
  func main() {
      t1 := T{
          X: 1,
          Y: "lei",
          Z: []int{1, 2, 3},
          M: map[string]int{
              "a": 1,
              "b": 2,
          },
      }
  
      t2 := T{
          X: 1,
          Y: "lei",
          Z: []int{1, 2, 3},
          M: map[string]int{
              "a": 1,
              "b": 2,
          },
      }
  
      fmt.Println(t2 == t1)
      //error - invalid operation: t2 == t1 (struct containing []int cannot be compared)
  
      fmt.Println(reflect.ValueOf(t2) == reflect.ValueOf(t1))
      //false
      fmt.Println(reflect.TypeOf(t2) == reflect.TypeOf(t1))
      //true
  
      //Update: slice or map
      a1 := []int{1, 2, 3, 4}
      a2 := []int{1, 2, 3, 4}
  
      fmt.Println(a1 == a2)
      //invalid operation: a1 == a2 (slice can only be compared to nil)
  
      m1 := map[string]int{
          "a": 1,
          "b": 2,
      }
      m2 := map[string]int{
          "a": 1,
          "b": 2,
      }
      fmt.Println(m1 == m2)
      // m1 == m2 (map can only be compared to nil)
  }
  </code></pre>
  
  <p><a href="http://play.golang.org/p/AZIzW2WunI" rel="noreferrer">http://play.golang.org/p/AZIzW2WunI</a></p>