Edited at

power of reflect.DeepEqual

More than 3 years have passed since last update.

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