LoginSignup
1
1

More than 5 years have passed since last update.

power of reflect.DeepEqual

Last updated at Posted at 2015-04-02

Greetings,

reflect.DeepEqual helped a lot this days, and somebody here asked how do you compare strings by strings.Join. so I thought I might share it here.

package main

import (
    "fmt"
    "reflect"
)

func main() {

    // map  
    m1 := map[string]string{"a": "b", "c": "d"}
    m2 := map[string]string{"a": "b", "c": "d"} 

    // slice
    a1 := []int{1, 2, 3}
    a2 := []int{1, 2, 3,}

    // map equality
    mapsAreEq := reflect.DeepEqual(m1, m2)
    fmt.Println(mapsAreEq)

    // slices equality
    slicesAreEq := reflect.DeepEqual(a1, a2)
    fmt.Println(slicesAreEq)    
}

reflect.DeepEqual takes an interface{} type parameter, so basically, you can pass anything on it(so be careful with it).

func DeepEqual(a1, a2 interface{}) bool

thats it!, hope it may do good for you too :D

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1