From b6608cd32dc36290b4318e256dd4e1bf0ce171cb Mon Sep 17 00:00:00 2001 From: Johan de Klerk <johan@shiplogic.com> Date: Fri, 2 Sep 2022 08:48:57 +0200 Subject: [PATCH] Verify audit event types --- audit/audit.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/audit/audit.go b/audit/audit.go index 2b46667..e7c2055 100644 --- a/audit/audit.go +++ b/audit/audit.go @@ -2,6 +2,7 @@ package audit import ( "encoding/json" + "gitlab.com/uafrica/go-utils/errors" "reflect" "regexp" "strconv" @@ -17,6 +18,19 @@ type FieldChange struct { To interface{} `json:"change_to"` } +func VerifyAuditEvents(original interface{}, new interface{}) error { + structValue := reflect.ValueOf(original) + if structValue.Kind() != reflect.Struct { + return errors.New("original object is not of type struct") + } + + structValue = reflect.ValueOf(new) + if structValue.Kind() != reflect.Struct { + return errors.New("new object is not of type struct") + } + return nil +} + func GetChanges(original interface{}, new interface{}) (map[string]interface{}, error) { changes := map[string]interface{}{} changelog, err := diff.Diff(original, new) -- GitLab