From 024ba500230f4e09e9052a099f682538498eb217 Mon Sep 17 00:00:00 2001 From: Johan de Klerk <johan@shiplogic.com> Date: Tue, 13 Jun 2023 13:14:54 +0200 Subject: [PATCH] Added IsEqual function --- utils/utils.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/utils/utils.go b/utils/utils.go index 64e0101..1252424 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -1,12 +1,14 @@ package utils import ( + "bytes" "github.com/mohae/deepcopy" "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/errors" "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/string_utils" "net/mail" "net/url" "os" + "reflect" "regexp" "strings" ) @@ -145,3 +147,26 @@ func EscapeOpenSearchSearchString(str string) string { } return searchString } + +// IsEqual returns if the two objects are equal +func IsEqual(expected interface{}, actual interface{}) bool { + if expected == nil || actual == nil { + return expected == actual + } + + if exp, ok := expected.([]byte); ok { + act, ok := actual.([]byte) + if !ok { + return false + } + + if exp == nil || act == nil { + return true + } + + return bytes.Equal(exp, act) + } + + return reflect.DeepEqual(expected, actual) + +} -- GitLab