From 3b9aa032e410fa04f77b57675f2add4e19988eb2 Mon Sep 17 00:00:00 2001 From: Zlatko Bratkovic Date: Thu, 30 Nov 2023 21:32:51 +0100 Subject: [PATCH] BUG/MAJOR: equal: check for nil before calling equal on models that have Equal method we need to check first if any of the values is nil --- cmd/struct_equal_generator/generate.go | 11 +- cmd/struct_equal_generator/generate.tmpl | 38 +- cmd/struct_equal_generator/main.go | 8 +- models/backend_compare.go | 880 +++++++++++++++++++++-- models/bind_compare.go | 1 + models/cluster_settings_compare.go | 40 +- models/default_bind_compare.go | 1 + models/default_server_compare.go | 1 + models/defaults_compare.go | 760 +++++++++++++++++++- models/fcgi_log_stderr_compare.go | 40 +- models/frontend_compare.go | 360 +++++++++- models/global_compare.go | 241 ++++++- models/info_compare.go | 164 ++++- models/native_stat_compare.go | 40 +- models/peer_section_compare.go | 81 ++- models/process_info_compare.go | 40 +- models/server_compare.go | 1 + models/server_template_compare.go | 1 + models/site_compare.go | 121 +++- models/spoe_message_compare.go | 41 +- models/ssl_certificate_compare.go | 106 ++- 21 files changed, 2823 insertions(+), 153 deletions(-) diff --git a/cmd/struct_equal_generator/generate.go b/cmd/struct_equal_generator/generate.go index e6d0d7c8..7f8ca405 100644 --- a/cmd/struct_equal_generator/generate.go +++ b/cmd/struct_equal_generator/generate.go @@ -7,11 +7,12 @@ import ( func generateEqualAndDiff(opt generateEqualAndDiffOptions) error { funcMaps := template.FuncMap{ - "HasPrefix": strings.HasPrefix, - "Title": toTitle, - "CamelCase": toCamelCase, - "LowerCase": toLowerCase, - "JSON": toJSON, + "HasPrefix": strings.HasPrefix, + "TrimPrefix": strings.TrimPrefix, + "Title": toTitle, + "CamelCase": toCamelCase, + "LowerCase": toLowerCase, + "JSON": toJSON, } tmpl, err := template.New("generate.tmpl").Funcs(funcMaps).Parse(tmplEqualAndDiff) if err != nil { diff --git a/cmd/struct_equal_generator/generate.tmpl b/cmd/struct_equal_generator/generate.tmpl index a291849a..93531acf 100644 --- a/cmd/struct_equal_generator/generate.tmpl +++ b/cmd/struct_equal_generator/generate.tmpl @@ -40,7 +40,43 @@ func (s {{.Data.Name}}) {{.Name}}(t {{.Data.Name}}, opts ...Options) {{- if eq $ {{- end }} } {{- else if or .HasEqual .HasEqualOpt }} - if !s.{{.Name}}.Equal({{if HasPrefix .Type "*"}}*{{end}}t.{{.Name}}{{if .HasEqualOpt}}, opt{{end}}) { + {{if HasPrefix .Type "*"}} + if s.{{.Name}} == nil || t.{{.Name}} == nil { + if s.{{.Name}} != nil || t.{{.Name}} != nil { + if opt.NilSameAsEmpty { + {{- if eq .TypeInFile "" }} + empty := &{{ TrimPrefix .Type "*"}}{} + {{- else }} + empty := &{{ TrimPrefix .TypeInFile "*"}}{} + {{- end }} + if s.{{.Name}} == nil { + if !(t.{{.Name}}.Equal(*empty)){ + {{- if eq $topLevel.Name "Equal" }} + return false + {{- else if eq $topLevel.Name "Diff" }} + diff["{{.Name}}"] = []interface{}{ {{if HasPrefix .Type "*"}}ValueOrNil({{end}}s.{{.Name}}{{if HasPrefix .Type "*"}}){{end}}, {{if HasPrefix .Type "*"}}ValueOrNil({{end}}t.{{.Name}}{{if HasPrefix .Type "*"}}){{end}} } + {{- end }} + } + } + if t.{{.Name}} == nil { + if !(s.{{.Name}}.Equal(*empty)){ + {{- if eq $topLevel.Name "Equal" }} + return false + {{- else if eq $topLevel.Name "Diff" }} + diff["{{.Name}}"] = []interface{}{ {{if HasPrefix .Type "*"}}ValueOrNil({{end}}s.{{.Name}}{{if HasPrefix .Type "*"}}){{end}}, {{if HasPrefix .Type "*"}}ValueOrNil({{end}}t.{{.Name}}{{if HasPrefix .Type "*"}}){{end}} } + {{- end }} + } + } + } else { + {{- if eq $topLevel.Name "Equal" }} + return false + {{- else if eq $topLevel.Name "Diff" }} + diff["{{.Name}}"] = []interface{}{ {{if HasPrefix .Type "*"}}ValueOrNil({{end}}s.{{.Name}}{{if HasPrefix .Type "*"}}){{end}}, {{if HasPrefix .Type "*"}}ValueOrNil({{end}}t.{{.Name}}{{if HasPrefix .Type "*"}}){{end}} } + {{- end }} + } + } + {{- end}} + {{if HasPrefix .Type "*"}} } else {{end}}if !s.{{.Name}}.Equal({{if HasPrefix .Type "*"}}*{{end}}t.{{.Name}}{{if .HasEqualOpt}}, opt{{end}}) { {{- if eq $topLevel.Name "Equal" }} return false {{- else if eq $topLevel.Name "Diff" }} diff --git a/cmd/struct_equal_generator/main.go b/cmd/struct_equal_generator/main.go index 4a10c6b2..66c7a218 100644 --- a/cmd/struct_equal_generator/main.go +++ b/cmd/struct_equal_generator/main.go @@ -71,7 +71,7 @@ func scanAllTypes(fileName string) []string { return typesInFile } -func generate(fileName string, args Args) (string, error) { //nolint:gocognit +func generate(fileName string, args Args) (string, error) { //nolint:gocognit,maintidx fset := token.NewFileSet() var packageName string @@ -165,6 +165,12 @@ func generate(fileName string, args Args) (string, error) { //nolint:gocognit needsOptions := false needsOptionsIndex := false fields, needsOptions, needsOptionsIndex = getFields(fields, currType, imports) + for _, f := range fields { + if strings.HasPrefix(f.Type, "*") && (f.HasEqualOpt || f.HasEqual) { + needsOptions = true + break + } + } hasTests = true err = generateEqualAndDiff(generateEqualAndDiffOptions{ PackageName: packageName, diff --git a/models/backend_compare.go b/models/backend_compare.go index ef1cb2de..76a3a5a5 100644 --- a/models/backend_compare.go +++ b/models/backend_compare.go @@ -73,7 +73,25 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } - if !s.Balance.Equal(*t.Balance, opt) { + if s.Balance == nil || t.Balance == nil { + if s.Balance != nil || t.Balance != nil { + if opt.NilSameAsEmpty { + empty := &Balance{} + if s.Balance == nil { + if !(t.Balance.Equal(*empty)) { + return false + } + } + if t.Balance == nil { + if !(s.Balance.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Balance.Equal(*t.Balance, opt) { return false } @@ -89,7 +107,25 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } - if !s.Compression.Equal(*t.Compression, opt) { + if s.Compression == nil || t.Compression == nil { + if s.Compression != nil || t.Compression != nil { + if opt.NilSameAsEmpty { + empty := &Compression{} + if s.Compression == nil { + if !(t.Compression.Equal(*empty)) { + return false + } + } + if t.Compression == nil { + if !(s.Compression.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Compression.Equal(*t.Compression, opt) { return false } @@ -97,11 +133,47 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } - if !s.Cookie.Equal(*t.Cookie, opt) { + if s.Cookie == nil || t.Cookie == nil { + if s.Cookie != nil || t.Cookie != nil { + if opt.NilSameAsEmpty { + empty := &Cookie{} + if s.Cookie == nil { + if !(t.Cookie.Equal(*empty)) { + return false + } + } + if t.Cookie == nil { + if !(s.Cookie.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Cookie.Equal(*t.Cookie, opt) { return false } - if !s.DefaultServer.Equal(*t.DefaultServer, opt) { + if s.DefaultServer == nil || t.DefaultServer == nil { + if s.DefaultServer != nil || t.DefaultServer != nil { + if opt.NilSameAsEmpty { + empty := &DefaultServer{} + if s.DefaultServer == nil { + if !(t.DefaultServer.Equal(*empty)) { + return false + } + } + if t.DefaultServer == nil { + if !(s.DefaultServer.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.DefaultServer.Equal(*t.DefaultServer, opt) { return false } @@ -117,7 +189,25 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } - if !s.EmailAlert.Equal(*t.EmailAlert, opt) { + if s.EmailAlert == nil || t.EmailAlert == nil { + if s.EmailAlert != nil || t.EmailAlert != nil { + if opt.NilSameAsEmpty { + empty := &EmailAlert{} + if s.EmailAlert == nil { + if !(t.EmailAlert.Equal(*empty)) { + return false + } + } + if t.EmailAlert == nil { + if !(s.EmailAlert.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.EmailAlert.Equal(*t.EmailAlert, opt) { return false } @@ -125,11 +215,47 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } - if !s.Errorloc302.Equal(*t.Errorloc302, opt) { + if s.Errorloc302 == nil || t.Errorloc302 == nil { + if s.Errorloc302 != nil || t.Errorloc302 != nil { + if opt.NilSameAsEmpty { + empty := &Errorloc{} + if s.Errorloc302 == nil { + if !(t.Errorloc302.Equal(*empty)) { + return false + } + } + if t.Errorloc302 == nil { + if !(s.Errorloc302.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Errorloc302.Equal(*t.Errorloc302, opt) { return false } - if !s.Errorloc303.Equal(*t.Errorloc303, opt) { + if s.Errorloc303 == nil || t.Errorloc303 == nil { + if s.Errorloc303 != nil || t.Errorloc303 != nil { + if opt.NilSameAsEmpty { + empty := &Errorloc{} + if s.Errorloc303 == nil { + if !(t.Errorloc303.Equal(*empty)) { + return false + } + } + if t.Errorloc303 == nil { + if !(s.Errorloc303.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Errorloc303.Equal(*t.Errorloc303, opt) { return false } @@ -145,11 +271,47 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } - if !s.ForcePersist.Equal(*t.ForcePersist, opt) { + if s.ForcePersist == nil || t.ForcePersist == nil { + if s.ForcePersist != nil || t.ForcePersist != nil { + if opt.NilSameAsEmpty { + empty := &BackendForcePersist{} + if s.ForcePersist == nil { + if !(t.ForcePersist.Equal(*empty)) { + return false + } + } + if t.ForcePersist == nil { + if !(s.ForcePersist.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.ForcePersist.Equal(*t.ForcePersist, opt) { return false } - if !s.Forwardfor.Equal(*t.Forwardfor, opt) { + if s.Forwardfor == nil || t.Forwardfor == nil { + if s.Forwardfor != nil || t.Forwardfor != nil { + if opt.NilSameAsEmpty { + empty := &Forwardfor{} + if s.Forwardfor == nil { + if !(t.Forwardfor.Equal(*empty)) { + return false + } + } + if t.Forwardfor == nil { + if !(s.Forwardfor.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Forwardfor.Equal(*t.Forwardfor, opt) { return false } @@ -165,7 +327,25 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } - if !s.HashType.Equal(*t.HashType, opt) { + if s.HashType == nil || t.HashType == nil { + if s.HashType != nil || t.HashType != nil { + if opt.NilSameAsEmpty { + empty := &HashType{} + if s.HashType == nil { + if !(t.HashType.Equal(*empty)) { + return false + } + } + if t.HashType == nil { + if !(s.HashType.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.HashType.Equal(*t.HashType, opt) { return false } @@ -173,7 +353,25 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } - if !s.HTTPCheck.Equal(*t.HTTPCheck, opt) { + if s.HTTPCheck == nil || t.HTTPCheck == nil { + if s.HTTPCheck != nil || t.HTTPCheck != nil { + if opt.NilSameAsEmpty { + empty := &HTTPCheck{} + if s.HTTPCheck == nil { + if !(t.HTTPCheck.Equal(*empty)) { + return false + } + } + if t.HTTPCheck == nil { + if !(s.HTTPCheck.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.HTTPCheck.Equal(*t.HTTPCheck, opt) { return false } @@ -225,7 +423,25 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } - if !s.HttpchkParams.Equal(*t.HttpchkParams, opt) { + if s.HttpchkParams == nil || t.HttpchkParams == nil { + if s.HttpchkParams != nil || t.HttpchkParams != nil { + if opt.NilSameAsEmpty { + empty := &HttpchkParams{} + if s.HttpchkParams == nil { + if !(t.HttpchkParams.Equal(*empty)) { + return false + } + } + if t.HttpchkParams == nil { + if !(s.HttpchkParams.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.HttpchkParams.Equal(*t.HttpchkParams, opt) { return false } @@ -237,7 +453,25 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } - if !s.IgnorePersist.Equal(*t.IgnorePersist, opt) { + if s.IgnorePersist == nil || t.IgnorePersist == nil { + if s.IgnorePersist != nil || t.IgnorePersist != nil { + if opt.NilSameAsEmpty { + empty := &BackendIgnorePersist{} + if s.IgnorePersist == nil { + if !(t.IgnorePersist.Equal(*empty)) { + return false + } + } + if t.IgnorePersist == nil { + if !(s.IgnorePersist.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.IgnorePersist.Equal(*t.IgnorePersist, opt) { return false } @@ -265,7 +499,25 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } - if !s.MysqlCheckParams.Equal(*t.MysqlCheckParams, opt) { + if s.MysqlCheckParams == nil || t.MysqlCheckParams == nil { + if s.MysqlCheckParams != nil || t.MysqlCheckParams != nil { + if opt.NilSameAsEmpty { + empty := &MysqlCheckParams{} + if s.MysqlCheckParams == nil { + if !(t.MysqlCheckParams.Equal(*empty)) { + return false + } + } + if t.MysqlCheckParams == nil { + if !(s.MysqlCheckParams.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.MysqlCheckParams.Equal(*t.MysqlCheckParams, opt) { return false } @@ -277,7 +529,25 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } - if !s.Originalto.Equal(*t.Originalto, opt) { + if s.Originalto == nil || t.Originalto == nil { + if s.Originalto != nil || t.Originalto != nil { + if opt.NilSameAsEmpty { + empty := &Originalto{} + if s.Originalto == nil { + if !(t.Originalto.Equal(*empty)) { + return false + } + } + if t.Originalto == nil { + if !(s.Originalto.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Originalto.Equal(*t.Originalto, opt) { return false } @@ -285,11 +555,47 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } - if !s.PersistRule.Equal(*t.PersistRule, opt) { + if s.PersistRule == nil || t.PersistRule == nil { + if s.PersistRule != nil || t.PersistRule != nil { + if opt.NilSameAsEmpty { + empty := &PersistRule{} + if s.PersistRule == nil { + if !(t.PersistRule.Equal(*empty)) { + return false + } + } + if t.PersistRule == nil { + if !(s.PersistRule.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.PersistRule.Equal(*t.PersistRule, opt) { return false } - if !s.PgsqlCheckParams.Equal(*t.PgsqlCheckParams, opt) { + if s.PgsqlCheckParams == nil || t.PgsqlCheckParams == nil { + if s.PgsqlCheckParams != nil || t.PgsqlCheckParams != nil { + if opt.NilSameAsEmpty { + empty := &PgsqlCheckParams{} + if s.PgsqlCheckParams == nil { + if !(t.PgsqlCheckParams.Equal(*empty)) { + return false + } + } + if t.PgsqlCheckParams == nil { + if !(s.PgsqlCheckParams.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.PgsqlCheckParams.Equal(*t.PgsqlCheckParams, opt) { return false } @@ -301,7 +607,25 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } - if !s.Redispatch.Equal(*t.Redispatch, opt) { + if s.Redispatch == nil || t.Redispatch == nil { + if s.Redispatch != nil || t.Redispatch != nil { + if opt.NilSameAsEmpty { + empty := &Redispatch{} + if s.Redispatch == nil { + if !(t.Redispatch.Equal(*empty)) { + return false + } + } + if t.Redispatch == nil { + if !(s.Redispatch.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Redispatch.Equal(*t.Redispatch, opt) { return false } @@ -325,11 +649,47 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } - if !s.SmtpchkParams.Equal(*t.SmtpchkParams, opt) { + if s.SmtpchkParams == nil || t.SmtpchkParams == nil { + if s.SmtpchkParams != nil || t.SmtpchkParams != nil { + if opt.NilSameAsEmpty { + empty := &SmtpchkParams{} + if s.SmtpchkParams == nil { + if !(t.SmtpchkParams.Equal(*empty)) { + return false + } + } + if t.SmtpchkParams == nil { + if !(s.SmtpchkParams.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.SmtpchkParams.Equal(*t.SmtpchkParams, opt) { return false } - if !s.Source.Equal(*t.Source, opt) { + if s.Source == nil || t.Source == nil { + if s.Source != nil || t.Source != nil { + if opt.NilSameAsEmpty { + empty := &Source{} + if s.Source == nil { + if !(t.Source.Equal(*empty)) { + return false + } + } + if t.Source == nil { + if !(s.Source.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Source.Equal(*t.Source, opt) { return false } @@ -365,11 +725,47 @@ func (s Backend) Equal(t Backend, opts ...Options) bool { return false } - if !s.StatsOptions.Equal(*t.StatsOptions, opt) { + if s.StatsOptions == nil || t.StatsOptions == nil { + if s.StatsOptions != nil || t.StatsOptions != nil { + if opt.NilSameAsEmpty { + empty := &StatsOptions{} + if s.StatsOptions == nil { + if !(t.StatsOptions.Equal(*empty)) { + return false + } + } + if t.StatsOptions == nil { + if !(s.StatsOptions.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.StatsOptions.Equal(*t.StatsOptions, opt) { return false } - if !s.StickTable.Equal(*t.StickTable, opt) { + if s.StickTable == nil || t.StickTable == nil { + if s.StickTable != nil || t.StickTable != nil { + if opt.NilSameAsEmpty { + empty := &ConfigStickTable{} + if s.StickTable == nil { + if !(t.StickTable.Equal(*empty)) { + return false + } + } + if t.StickTable == nil { + if !(s.StickTable.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.StickTable.Equal(*t.StickTable, opt) { return false } @@ -467,7 +863,25 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["Allbackups"] = []interface{}{s.Allbackups, t.Allbackups} } - if !s.Balance.Equal(*t.Balance, opt) { + if s.Balance == nil || t.Balance == nil { + if s.Balance != nil || t.Balance != nil { + if opt.NilSameAsEmpty { + empty := &Balance{} + if s.Balance == nil { + if !(t.Balance.Equal(*empty)) { + diff["Balance"] = []interface{}{ValueOrNil(s.Balance), ValueOrNil(t.Balance)} + } + } + if t.Balance == nil { + if !(s.Balance.Equal(*empty)) { + diff["Balance"] = []interface{}{ValueOrNil(s.Balance), ValueOrNil(t.Balance)} + } + } + } else { + diff["Balance"] = []interface{}{ValueOrNil(s.Balance), ValueOrNil(t.Balance)} + } + } + } else if !s.Balance.Equal(*t.Balance, opt) { diff["Balance"] = []interface{}{ValueOrNil(s.Balance), ValueOrNil(t.Balance)} } @@ -483,7 +897,25 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["Checkcache"] = []interface{}{s.Checkcache, t.Checkcache} } - if !s.Compression.Equal(*t.Compression, opt) { + if s.Compression == nil || t.Compression == nil { + if s.Compression != nil || t.Compression != nil { + if opt.NilSameAsEmpty { + empty := &Compression{} + if s.Compression == nil { + if !(t.Compression.Equal(*empty)) { + diff["Compression"] = []interface{}{ValueOrNil(s.Compression), ValueOrNil(t.Compression)} + } + } + if t.Compression == nil { + if !(s.Compression.Equal(*empty)) { + diff["Compression"] = []interface{}{ValueOrNil(s.Compression), ValueOrNil(t.Compression)} + } + } + } else { + diff["Compression"] = []interface{}{ValueOrNil(s.Compression), ValueOrNil(t.Compression)} + } + } + } else if !s.Compression.Equal(*t.Compression, opt) { diff["Compression"] = []interface{}{ValueOrNil(s.Compression), ValueOrNil(t.Compression)} } @@ -491,11 +923,47 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["ConnectTimeout"] = []interface{}{ValueOrNil(s.ConnectTimeout), ValueOrNil(t.ConnectTimeout)} } - if !s.Cookie.Equal(*t.Cookie, opt) { + if s.Cookie == nil || t.Cookie == nil { + if s.Cookie != nil || t.Cookie != nil { + if opt.NilSameAsEmpty { + empty := &Cookie{} + if s.Cookie == nil { + if !(t.Cookie.Equal(*empty)) { + diff["Cookie"] = []interface{}{ValueOrNil(s.Cookie), ValueOrNil(t.Cookie)} + } + } + if t.Cookie == nil { + if !(s.Cookie.Equal(*empty)) { + diff["Cookie"] = []interface{}{ValueOrNil(s.Cookie), ValueOrNil(t.Cookie)} + } + } + } else { + diff["Cookie"] = []interface{}{ValueOrNil(s.Cookie), ValueOrNil(t.Cookie)} + } + } + } else if !s.Cookie.Equal(*t.Cookie, opt) { diff["Cookie"] = []interface{}{ValueOrNil(s.Cookie), ValueOrNil(t.Cookie)} } - if !s.DefaultServer.Equal(*t.DefaultServer, opt) { + if s.DefaultServer == nil || t.DefaultServer == nil { + if s.DefaultServer != nil || t.DefaultServer != nil { + if opt.NilSameAsEmpty { + empty := &DefaultServer{} + if s.DefaultServer == nil { + if !(t.DefaultServer.Equal(*empty)) { + diff["DefaultServer"] = []interface{}{ValueOrNil(s.DefaultServer), ValueOrNil(t.DefaultServer)} + } + } + if t.DefaultServer == nil { + if !(s.DefaultServer.Equal(*empty)) { + diff["DefaultServer"] = []interface{}{ValueOrNil(s.DefaultServer), ValueOrNil(t.DefaultServer)} + } + } + } else { + diff["DefaultServer"] = []interface{}{ValueOrNil(s.DefaultServer), ValueOrNil(t.DefaultServer)} + } + } + } else if !s.DefaultServer.Equal(*t.DefaultServer, opt) { diff["DefaultServer"] = []interface{}{ValueOrNil(s.DefaultServer), ValueOrNil(t.DefaultServer)} } @@ -511,7 +979,25 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["DynamicCookieKey"] = []interface{}{s.DynamicCookieKey, t.DynamicCookieKey} } - if !s.EmailAlert.Equal(*t.EmailAlert, opt) { + if s.EmailAlert == nil || t.EmailAlert == nil { + if s.EmailAlert != nil || t.EmailAlert != nil { + if opt.NilSameAsEmpty { + empty := &EmailAlert{} + if s.EmailAlert == nil { + if !(t.EmailAlert.Equal(*empty)) { + diff["EmailAlert"] = []interface{}{ValueOrNil(s.EmailAlert), ValueOrNil(t.EmailAlert)} + } + } + if t.EmailAlert == nil { + if !(s.EmailAlert.Equal(*empty)) { + diff["EmailAlert"] = []interface{}{ValueOrNil(s.EmailAlert), ValueOrNil(t.EmailAlert)} + } + } + } else { + diff["EmailAlert"] = []interface{}{ValueOrNil(s.EmailAlert), ValueOrNil(t.EmailAlert)} + } + } + } else if !s.EmailAlert.Equal(*t.EmailAlert, opt) { diff["EmailAlert"] = []interface{}{ValueOrNil(s.EmailAlert), ValueOrNil(t.EmailAlert)} } @@ -519,11 +1005,47 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["Enabled"] = []interface{}{s.Enabled, t.Enabled} } - if !s.Errorloc302.Equal(*t.Errorloc302, opt) { + if s.Errorloc302 == nil || t.Errorloc302 == nil { + if s.Errorloc302 != nil || t.Errorloc302 != nil { + if opt.NilSameAsEmpty { + empty := &Errorloc{} + if s.Errorloc302 == nil { + if !(t.Errorloc302.Equal(*empty)) { + diff["Errorloc302"] = []interface{}{ValueOrNil(s.Errorloc302), ValueOrNil(t.Errorloc302)} + } + } + if t.Errorloc302 == nil { + if !(s.Errorloc302.Equal(*empty)) { + diff["Errorloc302"] = []interface{}{ValueOrNil(s.Errorloc302), ValueOrNil(t.Errorloc302)} + } + } + } else { + diff["Errorloc302"] = []interface{}{ValueOrNil(s.Errorloc302), ValueOrNil(t.Errorloc302)} + } + } + } else if !s.Errorloc302.Equal(*t.Errorloc302, opt) { diff["Errorloc302"] = []interface{}{ValueOrNil(s.Errorloc302), ValueOrNil(t.Errorloc302)} } - if !s.Errorloc303.Equal(*t.Errorloc303, opt) { + if s.Errorloc303 == nil || t.Errorloc303 == nil { + if s.Errorloc303 != nil || t.Errorloc303 != nil { + if opt.NilSameAsEmpty { + empty := &Errorloc{} + if s.Errorloc303 == nil { + if !(t.Errorloc303.Equal(*empty)) { + diff["Errorloc303"] = []interface{}{ValueOrNil(s.Errorloc303), ValueOrNil(t.Errorloc303)} + } + } + if t.Errorloc303 == nil { + if !(s.Errorloc303.Equal(*empty)) { + diff["Errorloc303"] = []interface{}{ValueOrNil(s.Errorloc303), ValueOrNil(t.Errorloc303)} + } + } + } else { + diff["Errorloc303"] = []interface{}{ValueOrNil(s.Errorloc303), ValueOrNil(t.Errorloc303)} + } + } + } else if !s.Errorloc303.Equal(*t.Errorloc303, opt) { diff["Errorloc303"] = []interface{}{ValueOrNil(s.Errorloc303), ValueOrNil(t.Errorloc303)} } @@ -539,11 +1061,47 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["ExternalCheckPath"] = []interface{}{s.ExternalCheckPath, t.ExternalCheckPath} } - if !s.ForcePersist.Equal(*t.ForcePersist, opt) { + if s.ForcePersist == nil || t.ForcePersist == nil { + if s.ForcePersist != nil || t.ForcePersist != nil { + if opt.NilSameAsEmpty { + empty := &BackendForcePersist{} + if s.ForcePersist == nil { + if !(t.ForcePersist.Equal(*empty)) { + diff["ForcePersist"] = []interface{}{ValueOrNil(s.ForcePersist), ValueOrNil(t.ForcePersist)} + } + } + if t.ForcePersist == nil { + if !(s.ForcePersist.Equal(*empty)) { + diff["ForcePersist"] = []interface{}{ValueOrNil(s.ForcePersist), ValueOrNil(t.ForcePersist)} + } + } + } else { + diff["ForcePersist"] = []interface{}{ValueOrNil(s.ForcePersist), ValueOrNil(t.ForcePersist)} + } + } + } else if !s.ForcePersist.Equal(*t.ForcePersist, opt) { diff["ForcePersist"] = []interface{}{ValueOrNil(s.ForcePersist), ValueOrNil(t.ForcePersist)} } - if !s.Forwardfor.Equal(*t.Forwardfor, opt) { + if s.Forwardfor == nil || t.Forwardfor == nil { + if s.Forwardfor != nil || t.Forwardfor != nil { + if opt.NilSameAsEmpty { + empty := &Forwardfor{} + if s.Forwardfor == nil { + if !(t.Forwardfor.Equal(*empty)) { + diff["Forwardfor"] = []interface{}{ValueOrNil(s.Forwardfor), ValueOrNil(t.Forwardfor)} + } + } + if t.Forwardfor == nil { + if !(s.Forwardfor.Equal(*empty)) { + diff["Forwardfor"] = []interface{}{ValueOrNil(s.Forwardfor), ValueOrNil(t.Forwardfor)} + } + } + } else { + diff["Forwardfor"] = []interface{}{ValueOrNil(s.Forwardfor), ValueOrNil(t.Forwardfor)} + } + } + } else if !s.Forwardfor.Equal(*t.Forwardfor, opt) { diff["Forwardfor"] = []interface{}{ValueOrNil(s.Forwardfor), ValueOrNil(t.Forwardfor)} } @@ -559,7 +1117,25 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["H1CaseAdjustBogusServer"] = []interface{}{s.H1CaseAdjustBogusServer, t.H1CaseAdjustBogusServer} } - if !s.HashType.Equal(*t.HashType, opt) { + if s.HashType == nil || t.HashType == nil { + if s.HashType != nil || t.HashType != nil { + if opt.NilSameAsEmpty { + empty := &HashType{} + if s.HashType == nil { + if !(t.HashType.Equal(*empty)) { + diff["HashType"] = []interface{}{ValueOrNil(s.HashType), ValueOrNil(t.HashType)} + } + } + if t.HashType == nil { + if !(s.HashType.Equal(*empty)) { + diff["HashType"] = []interface{}{ValueOrNil(s.HashType), ValueOrNil(t.HashType)} + } + } + } else { + diff["HashType"] = []interface{}{ValueOrNil(s.HashType), ValueOrNil(t.HashType)} + } + } + } else if !s.HashType.Equal(*t.HashType, opt) { diff["HashType"] = []interface{}{ValueOrNil(s.HashType), ValueOrNil(t.HashType)} } @@ -567,7 +1143,25 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["HTTPBufferRequest"] = []interface{}{s.HTTPBufferRequest, t.HTTPBufferRequest} } - if !s.HTTPCheck.Equal(*t.HTTPCheck, opt) { + if s.HTTPCheck == nil || t.HTTPCheck == nil { + if s.HTTPCheck != nil || t.HTTPCheck != nil { + if opt.NilSameAsEmpty { + empty := &HTTPCheck{} + if s.HTTPCheck == nil { + if !(t.HTTPCheck.Equal(*empty)) { + diff["HTTPCheck"] = []interface{}{ValueOrNil(s.HTTPCheck), ValueOrNil(t.HTTPCheck)} + } + } + if t.HTTPCheck == nil { + if !(s.HTTPCheck.Equal(*empty)) { + diff["HTTPCheck"] = []interface{}{ValueOrNil(s.HTTPCheck), ValueOrNil(t.HTTPCheck)} + } + } + } else { + diff["HTTPCheck"] = []interface{}{ValueOrNil(s.HTTPCheck), ValueOrNil(t.HTTPCheck)} + } + } + } else if !s.HTTPCheck.Equal(*t.HTTPCheck, opt) { diff["HTTPCheck"] = []interface{}{ValueOrNil(s.HTTPCheck), ValueOrNil(t.HTTPCheck)} } @@ -619,7 +1213,25 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["HTTPSendNameHeader"] = []interface{}{ValueOrNil(s.HTTPSendNameHeader), ValueOrNil(t.HTTPSendNameHeader)} } - if !s.HttpchkParams.Equal(*t.HttpchkParams, opt) { + if s.HttpchkParams == nil || t.HttpchkParams == nil { + if s.HttpchkParams != nil || t.HttpchkParams != nil { + if opt.NilSameAsEmpty { + empty := &HttpchkParams{} + if s.HttpchkParams == nil { + if !(t.HttpchkParams.Equal(*empty)) { + diff["HttpchkParams"] = []interface{}{ValueOrNil(s.HttpchkParams), ValueOrNil(t.HttpchkParams)} + } + } + if t.HttpchkParams == nil { + if !(s.HttpchkParams.Equal(*empty)) { + diff["HttpchkParams"] = []interface{}{ValueOrNil(s.HttpchkParams), ValueOrNil(t.HttpchkParams)} + } + } + } else { + diff["HttpchkParams"] = []interface{}{ValueOrNil(s.HttpchkParams), ValueOrNil(t.HttpchkParams)} + } + } + } else if !s.HttpchkParams.Equal(*t.HttpchkParams, opt) { diff["HttpchkParams"] = []interface{}{ValueOrNil(s.HttpchkParams), ValueOrNil(t.HttpchkParams)} } @@ -631,7 +1243,25 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["ID"] = []interface{}{ValueOrNil(s.ID), ValueOrNil(t.ID)} } - if !s.IgnorePersist.Equal(*t.IgnorePersist, opt) { + if s.IgnorePersist == nil || t.IgnorePersist == nil { + if s.IgnorePersist != nil || t.IgnorePersist != nil { + if opt.NilSameAsEmpty { + empty := &BackendIgnorePersist{} + if s.IgnorePersist == nil { + if !(t.IgnorePersist.Equal(*empty)) { + diff["IgnorePersist"] = []interface{}{ValueOrNil(s.IgnorePersist), ValueOrNil(t.IgnorePersist)} + } + } + if t.IgnorePersist == nil { + if !(s.IgnorePersist.Equal(*empty)) { + diff["IgnorePersist"] = []interface{}{ValueOrNil(s.IgnorePersist), ValueOrNil(t.IgnorePersist)} + } + } + } else { + diff["IgnorePersist"] = []interface{}{ValueOrNil(s.IgnorePersist), ValueOrNil(t.IgnorePersist)} + } + } + } else if !s.IgnorePersist.Equal(*t.IgnorePersist, opt) { diff["IgnorePersist"] = []interface{}{ValueOrNil(s.IgnorePersist), ValueOrNil(t.IgnorePersist)} } @@ -659,7 +1289,25 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["Mode"] = []interface{}{s.Mode, t.Mode} } - if !s.MysqlCheckParams.Equal(*t.MysqlCheckParams, opt) { + if s.MysqlCheckParams == nil || t.MysqlCheckParams == nil { + if s.MysqlCheckParams != nil || t.MysqlCheckParams != nil { + if opt.NilSameAsEmpty { + empty := &MysqlCheckParams{} + if s.MysqlCheckParams == nil { + if !(t.MysqlCheckParams.Equal(*empty)) { + diff["MysqlCheckParams"] = []interface{}{ValueOrNil(s.MysqlCheckParams), ValueOrNil(t.MysqlCheckParams)} + } + } + if t.MysqlCheckParams == nil { + if !(s.MysqlCheckParams.Equal(*empty)) { + diff["MysqlCheckParams"] = []interface{}{ValueOrNil(s.MysqlCheckParams), ValueOrNil(t.MysqlCheckParams)} + } + } + } else { + diff["MysqlCheckParams"] = []interface{}{ValueOrNil(s.MysqlCheckParams), ValueOrNil(t.MysqlCheckParams)} + } + } + } else if !s.MysqlCheckParams.Equal(*t.MysqlCheckParams, opt) { diff["MysqlCheckParams"] = []interface{}{ValueOrNil(s.MysqlCheckParams), ValueOrNil(t.MysqlCheckParams)} } @@ -671,7 +1319,25 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["Nolinger"] = []interface{}{s.Nolinger, t.Nolinger} } - if !s.Originalto.Equal(*t.Originalto, opt) { + if s.Originalto == nil || t.Originalto == nil { + if s.Originalto != nil || t.Originalto != nil { + if opt.NilSameAsEmpty { + empty := &Originalto{} + if s.Originalto == nil { + if !(t.Originalto.Equal(*empty)) { + diff["Originalto"] = []interface{}{ValueOrNil(s.Originalto), ValueOrNil(t.Originalto)} + } + } + if t.Originalto == nil { + if !(s.Originalto.Equal(*empty)) { + diff["Originalto"] = []interface{}{ValueOrNil(s.Originalto), ValueOrNil(t.Originalto)} + } + } + } else { + diff["Originalto"] = []interface{}{ValueOrNil(s.Originalto), ValueOrNil(t.Originalto)} + } + } + } else if !s.Originalto.Equal(*t.Originalto, opt) { diff["Originalto"] = []interface{}{ValueOrNil(s.Originalto), ValueOrNil(t.Originalto)} } @@ -679,11 +1345,47 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["Persist"] = []interface{}{s.Persist, t.Persist} } - if !s.PersistRule.Equal(*t.PersistRule, opt) { + if s.PersistRule == nil || t.PersistRule == nil { + if s.PersistRule != nil || t.PersistRule != nil { + if opt.NilSameAsEmpty { + empty := &PersistRule{} + if s.PersistRule == nil { + if !(t.PersistRule.Equal(*empty)) { + diff["PersistRule"] = []interface{}{ValueOrNil(s.PersistRule), ValueOrNil(t.PersistRule)} + } + } + if t.PersistRule == nil { + if !(s.PersistRule.Equal(*empty)) { + diff["PersistRule"] = []interface{}{ValueOrNil(s.PersistRule), ValueOrNil(t.PersistRule)} + } + } + } else { + diff["PersistRule"] = []interface{}{ValueOrNil(s.PersistRule), ValueOrNil(t.PersistRule)} + } + } + } else if !s.PersistRule.Equal(*t.PersistRule, opt) { diff["PersistRule"] = []interface{}{ValueOrNil(s.PersistRule), ValueOrNil(t.PersistRule)} } - if !s.PgsqlCheckParams.Equal(*t.PgsqlCheckParams, opt) { + if s.PgsqlCheckParams == nil || t.PgsqlCheckParams == nil { + if s.PgsqlCheckParams != nil || t.PgsqlCheckParams != nil { + if opt.NilSameAsEmpty { + empty := &PgsqlCheckParams{} + if s.PgsqlCheckParams == nil { + if !(t.PgsqlCheckParams.Equal(*empty)) { + diff["PgsqlCheckParams"] = []interface{}{ValueOrNil(s.PgsqlCheckParams), ValueOrNil(t.PgsqlCheckParams)} + } + } + if t.PgsqlCheckParams == nil { + if !(s.PgsqlCheckParams.Equal(*empty)) { + diff["PgsqlCheckParams"] = []interface{}{ValueOrNil(s.PgsqlCheckParams), ValueOrNil(t.PgsqlCheckParams)} + } + } + } else { + diff["PgsqlCheckParams"] = []interface{}{ValueOrNil(s.PgsqlCheckParams), ValueOrNil(t.PgsqlCheckParams)} + } + } + } else if !s.PgsqlCheckParams.Equal(*t.PgsqlCheckParams, opt) { diff["PgsqlCheckParams"] = []interface{}{ValueOrNil(s.PgsqlCheckParams), ValueOrNil(t.PgsqlCheckParams)} } @@ -695,7 +1397,25 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["QueueTimeout"] = []interface{}{ValueOrNil(s.QueueTimeout), ValueOrNil(t.QueueTimeout)} } - if !s.Redispatch.Equal(*t.Redispatch, opt) { + if s.Redispatch == nil || t.Redispatch == nil { + if s.Redispatch != nil || t.Redispatch != nil { + if opt.NilSameAsEmpty { + empty := &Redispatch{} + if s.Redispatch == nil { + if !(t.Redispatch.Equal(*empty)) { + diff["Redispatch"] = []interface{}{ValueOrNil(s.Redispatch), ValueOrNil(t.Redispatch)} + } + } + if t.Redispatch == nil { + if !(s.Redispatch.Equal(*empty)) { + diff["Redispatch"] = []interface{}{ValueOrNil(s.Redispatch), ValueOrNil(t.Redispatch)} + } + } + } else { + diff["Redispatch"] = []interface{}{ValueOrNil(s.Redispatch), ValueOrNil(t.Redispatch)} + } + } + } else if !s.Redispatch.Equal(*t.Redispatch, opt) { diff["Redispatch"] = []interface{}{ValueOrNil(s.Redispatch), ValueOrNil(t.Redispatch)} } @@ -719,11 +1439,47 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["ServerTimeout"] = []interface{}{ValueOrNil(s.ServerTimeout), ValueOrNil(t.ServerTimeout)} } - if !s.SmtpchkParams.Equal(*t.SmtpchkParams, opt) { + if s.SmtpchkParams == nil || t.SmtpchkParams == nil { + if s.SmtpchkParams != nil || t.SmtpchkParams != nil { + if opt.NilSameAsEmpty { + empty := &SmtpchkParams{} + if s.SmtpchkParams == nil { + if !(t.SmtpchkParams.Equal(*empty)) { + diff["SmtpchkParams"] = []interface{}{ValueOrNil(s.SmtpchkParams), ValueOrNil(t.SmtpchkParams)} + } + } + if t.SmtpchkParams == nil { + if !(s.SmtpchkParams.Equal(*empty)) { + diff["SmtpchkParams"] = []interface{}{ValueOrNil(s.SmtpchkParams), ValueOrNil(t.SmtpchkParams)} + } + } + } else { + diff["SmtpchkParams"] = []interface{}{ValueOrNil(s.SmtpchkParams), ValueOrNil(t.SmtpchkParams)} + } + } + } else if !s.SmtpchkParams.Equal(*t.SmtpchkParams, opt) { diff["SmtpchkParams"] = []interface{}{ValueOrNil(s.SmtpchkParams), ValueOrNil(t.SmtpchkParams)} } - if !s.Source.Equal(*t.Source, opt) { + if s.Source == nil || t.Source == nil { + if s.Source != nil || t.Source != nil { + if opt.NilSameAsEmpty { + empty := &Source{} + if s.Source == nil { + if !(t.Source.Equal(*empty)) { + diff["Source"] = []interface{}{ValueOrNil(s.Source), ValueOrNil(t.Source)} + } + } + if t.Source == nil { + if !(s.Source.Equal(*empty)) { + diff["Source"] = []interface{}{ValueOrNil(s.Source), ValueOrNil(t.Source)} + } + } + } else { + diff["Source"] = []interface{}{ValueOrNil(s.Source), ValueOrNil(t.Source)} + } + } + } else if !s.Source.Equal(*t.Source, opt) { diff["Source"] = []interface{}{ValueOrNil(s.Source), ValueOrNil(t.Source)} } @@ -759,11 +1515,47 @@ func (s Backend) Diff(t Backend, opts ...Options) map[string][]interface{} { diff["SrvtcpkaIntvl"] = []interface{}{ValueOrNil(s.SrvtcpkaIntvl), ValueOrNil(t.SrvtcpkaIntvl)} } - if !s.StatsOptions.Equal(*t.StatsOptions, opt) { + if s.StatsOptions == nil || t.StatsOptions == nil { + if s.StatsOptions != nil || t.StatsOptions != nil { + if opt.NilSameAsEmpty { + empty := &StatsOptions{} + if s.StatsOptions == nil { + if !(t.StatsOptions.Equal(*empty)) { + diff["StatsOptions"] = []interface{}{ValueOrNil(s.StatsOptions), ValueOrNil(t.StatsOptions)} + } + } + if t.StatsOptions == nil { + if !(s.StatsOptions.Equal(*empty)) { + diff["StatsOptions"] = []interface{}{ValueOrNil(s.StatsOptions), ValueOrNil(t.StatsOptions)} + } + } + } else { + diff["StatsOptions"] = []interface{}{ValueOrNil(s.StatsOptions), ValueOrNil(t.StatsOptions)} + } + } + } else if !s.StatsOptions.Equal(*t.StatsOptions, opt) { diff["StatsOptions"] = []interface{}{ValueOrNil(s.StatsOptions), ValueOrNil(t.StatsOptions)} } - if !s.StickTable.Equal(*t.StickTable, opt) { + if s.StickTable == nil || t.StickTable == nil { + if s.StickTable != nil || t.StickTable != nil { + if opt.NilSameAsEmpty { + empty := &ConfigStickTable{} + if s.StickTable == nil { + if !(t.StickTable.Equal(*empty)) { + diff["StickTable"] = []interface{}{ValueOrNil(s.StickTable), ValueOrNil(t.StickTable)} + } + } + if t.StickTable == nil { + if !(s.StickTable.Equal(*empty)) { + diff["StickTable"] = []interface{}{ValueOrNil(s.StickTable), ValueOrNil(t.StickTable)} + } + } + } else { + diff["StickTable"] = []interface{}{ValueOrNil(s.StickTable), ValueOrNil(t.StickTable)} + } + } + } else if !s.StickTable.Equal(*t.StickTable, opt) { diff["StickTable"] = []interface{}{ValueOrNil(s.StickTable), ValueOrNil(t.StickTable)} } diff --git a/models/bind_compare.go b/models/bind_compare.go index bd0f823b..7b69fd70 100644 --- a/models/bind_compare.go +++ b/models/bind_compare.go @@ -69,6 +69,7 @@ func (s Bind) Diff(t Bind, opts ...Options) map[string][]interface{} { opt := getOptions(opts...) diff := make(map[string][]interface{}) + if !s.BindParams.Equal(t.BindParams, opt) { diff["BindParams"] = []interface{}{s.BindParams, t.BindParams} } diff --git a/models/cluster_settings_compare.go b/models/cluster_settings_compare.go index 9ccc725e..68c33807 100644 --- a/models/cluster_settings_compare.go +++ b/models/cluster_settings_compare.go @@ -41,7 +41,25 @@ func (s ClusterSettings) Equal(t ClusterSettings, opts ...Options) bool { return false } - if !s.Cluster.Equal(*t.Cluster, opt) { + if s.Cluster == nil || t.Cluster == nil { + if s.Cluster != nil || t.Cluster != nil { + if opt.NilSameAsEmpty { + empty := &ClusterSettingsCluster{} + if s.Cluster == nil { + if !(t.Cluster.Equal(*empty)) { + return false + } + } + if t.Cluster == nil { + if !(s.Cluster.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Cluster.Equal(*t.Cluster, opt) { return false } @@ -77,7 +95,25 @@ func (s ClusterSettings) Diff(t ClusterSettings, opts ...Options) map[string][]i diff["BootstrapKey"] = []interface{}{s.BootstrapKey, t.BootstrapKey} } - if !s.Cluster.Equal(*t.Cluster, opt) { + if s.Cluster == nil || t.Cluster == nil { + if s.Cluster != nil || t.Cluster != nil { + if opt.NilSameAsEmpty { + empty := &ClusterSettingsCluster{} + if s.Cluster == nil { + if !(t.Cluster.Equal(*empty)) { + diff["Cluster"] = []interface{}{ValueOrNil(s.Cluster), ValueOrNil(t.Cluster)} + } + } + if t.Cluster == nil { + if !(s.Cluster.Equal(*empty)) { + diff["Cluster"] = []interface{}{ValueOrNil(s.Cluster), ValueOrNil(t.Cluster)} + } + } + } else { + diff["Cluster"] = []interface{}{ValueOrNil(s.Cluster), ValueOrNil(t.Cluster)} + } + } + } else if !s.Cluster.Equal(*t.Cluster, opt) { diff["Cluster"] = []interface{}{ValueOrNil(s.Cluster), ValueOrNil(t.Cluster)} } diff --git a/models/default_bind_compare.go b/models/default_bind_compare.go index 723bc578..139ff24e 100644 --- a/models/default_bind_compare.go +++ b/models/default_bind_compare.go @@ -57,6 +57,7 @@ func (s DefaultBind) Diff(t DefaultBind, opts ...Options) map[string][]interface opt := getOptions(opts...) diff := make(map[string][]interface{}) + if !s.BindParams.Equal(t.BindParams, opt) { diff["BindParams"] = []interface{}{s.BindParams, t.BindParams} } diff --git a/models/default_server_compare.go b/models/default_server_compare.go index 2b70d3c7..ed2a980f 100644 --- a/models/default_server_compare.go +++ b/models/default_server_compare.go @@ -57,6 +57,7 @@ func (s DefaultServer) Diff(t DefaultServer, opts ...Options) map[string][]inter opt := getOptions(opts...) diff := make(map[string][]interface{}) + if !s.ServerParams.Equal(t.ServerParams, opt) { diff["ServerParams"] = []interface{}{s.ServerParams, t.ServerParams} } diff --git a/models/defaults_compare.go b/models/defaults_compare.go index c53cc10e..5089cb4d 100644 --- a/models/defaults_compare.go +++ b/models/defaults_compare.go @@ -81,7 +81,25 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.Balance.Equal(*t.Balance, opt) { + if s.Balance == nil || t.Balance == nil { + if s.Balance != nil || t.Balance != nil { + if opt.NilSameAsEmpty { + empty := &Balance{} + if s.Balance == nil { + if !(t.Balance.Equal(*empty)) { + return false + } + } + if t.Balance == nil { + if !(s.Balance.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Balance.Equal(*t.Balance, opt) { return false } @@ -125,7 +143,25 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.Compression.Equal(*t.Compression, opt) { + if s.Compression == nil || t.Compression == nil { + if s.Compression != nil || t.Compression != nil { + if opt.NilSameAsEmpty { + empty := &Compression{} + if s.Compression == nil { + if !(t.Compression.Equal(*empty)) { + return false + } + } + if t.Compression == nil { + if !(s.Compression.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Compression.Equal(*t.Compression, opt) { return false } @@ -137,7 +173,25 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.Cookie.Equal(*t.Cookie, opt) { + if s.Cookie == nil || t.Cookie == nil { + if s.Cookie != nil || t.Cookie != nil { + if opt.NilSameAsEmpty { + empty := &Cookie{} + if s.Cookie == nil { + if !(t.Cookie.Equal(*empty)) { + return false + } + } + if t.Cookie == nil { + if !(s.Cookie.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Cookie.Equal(*t.Cookie, opt) { return false } @@ -145,7 +199,25 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.DefaultServer.Equal(*t.DefaultServer, opt) { + if s.DefaultServer == nil || t.DefaultServer == nil { + if s.DefaultServer != nil || t.DefaultServer != nil { + if opt.NilSameAsEmpty { + empty := &DefaultServer{} + if s.DefaultServer == nil { + if !(t.DefaultServer.Equal(*empty)) { + return false + } + } + if t.DefaultServer == nil { + if !(s.DefaultServer.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.DefaultServer.Equal(*t.DefaultServer, opt) { return false } @@ -169,7 +241,25 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.EmailAlert.Equal(*t.EmailAlert, opt) { + if s.EmailAlert == nil || t.EmailAlert == nil { + if s.EmailAlert != nil || t.EmailAlert != nil { + if opt.NilSameAsEmpty { + empty := &EmailAlert{} + if s.EmailAlert == nil { + if !(t.EmailAlert.Equal(*empty)) { + return false + } + } + if t.EmailAlert == nil { + if !(s.EmailAlert.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.EmailAlert.Equal(*t.EmailAlert, opt) { return false } @@ -181,11 +271,47 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.Errorloc302.Equal(*t.Errorloc302, opt) { + if s.Errorloc302 == nil || t.Errorloc302 == nil { + if s.Errorloc302 != nil || t.Errorloc302 != nil { + if opt.NilSameAsEmpty { + empty := &Errorloc{} + if s.Errorloc302 == nil { + if !(t.Errorloc302.Equal(*empty)) { + return false + } + } + if t.Errorloc302 == nil { + if !(s.Errorloc302.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Errorloc302.Equal(*t.Errorloc302, opt) { return false } - if !s.Errorloc303.Equal(*t.Errorloc303, opt) { + if s.Errorloc303 == nil || t.Errorloc303 == nil { + if s.Errorloc303 != nil || t.Errorloc303 != nil { + if opt.NilSameAsEmpty { + empty := &Errorloc{} + if s.Errorloc303 == nil { + if !(t.Errorloc303.Equal(*empty)) { + return false + } + } + if t.Errorloc303 == nil { + if !(s.Errorloc303.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Errorloc303.Equal(*t.Errorloc303, opt) { return false } @@ -201,7 +327,25 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.Forwardfor.Equal(*t.Forwardfor, opt) { + if s.Forwardfor == nil || t.Forwardfor == nil { + if s.Forwardfor != nil || t.Forwardfor != nil { + if opt.NilSameAsEmpty { + empty := &Forwardfor{} + if s.Forwardfor == nil { + if !(t.Forwardfor.Equal(*empty)) { + return false + } + } + if t.Forwardfor == nil { + if !(s.Forwardfor.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Forwardfor.Equal(*t.Forwardfor, opt) { return false } @@ -221,7 +365,25 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.HashType.Equal(*t.HashType, opt) { + if s.HashType == nil || t.HashType == nil { + if s.HashType != nil || t.HashType != nil { + if opt.NilSameAsEmpty { + empty := &HashType{} + if s.HashType == nil { + if !(t.HashType.Equal(*empty)) { + return false + } + } + if t.HashType == nil { + if !(s.HashType.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.HashType.Equal(*t.HashType, opt) { return false } @@ -229,7 +391,25 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.HTTPCheck.Equal(*t.HTTPCheck, opt) { + if s.HTTPCheck == nil || t.HTTPCheck == nil { + if s.HTTPCheck != nil || t.HTTPCheck != nil { + if opt.NilSameAsEmpty { + empty := &HTTPCheck{} + if s.HTTPCheck == nil { + if !(t.HTTPCheck.Equal(*empty)) { + return false + } + } + if t.HTTPCheck == nil { + if !(s.HTTPCheck.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.HTTPCheck.Equal(*t.HTTPCheck, opt) { return false } @@ -277,7 +457,25 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.HttpchkParams.Equal(*t.HttpchkParams, opt) { + if s.HttpchkParams == nil || t.HttpchkParams == nil { + if s.HttpchkParams != nil || t.HttpchkParams != nil { + if opt.NilSameAsEmpty { + empty := &HttpchkParams{} + if s.HttpchkParams == nil { + if !(t.HttpchkParams.Equal(*empty)) { + return false + } + } + if t.HttpchkParams == nil { + if !(s.HttpchkParams.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.HttpchkParams.Equal(*t.HttpchkParams, opt) { return false } @@ -341,7 +539,25 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.MysqlCheckParams.Equal(*t.MysqlCheckParams, opt) { + if s.MysqlCheckParams == nil || t.MysqlCheckParams == nil { + if s.MysqlCheckParams != nil || t.MysqlCheckParams != nil { + if opt.NilSameAsEmpty { + empty := &MysqlCheckParams{} + if s.MysqlCheckParams == nil { + if !(t.MysqlCheckParams.Equal(*empty)) { + return false + } + } + if t.MysqlCheckParams == nil { + if !(s.MysqlCheckParams.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.MysqlCheckParams.Equal(*t.MysqlCheckParams, opt) { return false } @@ -353,7 +569,25 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.Originalto.Equal(*t.Originalto, opt) { + if s.Originalto == nil || t.Originalto == nil { + if s.Originalto != nil || t.Originalto != nil { + if opt.NilSameAsEmpty { + empty := &Originalto{} + if s.Originalto == nil { + if !(t.Originalto.Equal(*empty)) { + return false + } + } + if t.Originalto == nil { + if !(s.Originalto.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Originalto.Equal(*t.Originalto, opt) { return false } @@ -361,11 +595,47 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.PersistRule.Equal(*t.PersistRule, opt) { + if s.PersistRule == nil || t.PersistRule == nil { + if s.PersistRule != nil || t.PersistRule != nil { + if opt.NilSameAsEmpty { + empty := &PersistRule{} + if s.PersistRule == nil { + if !(t.PersistRule.Equal(*empty)) { + return false + } + } + if t.PersistRule == nil { + if !(s.PersistRule.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.PersistRule.Equal(*t.PersistRule, opt) { return false } - if !s.PgsqlCheckParams.Equal(*t.PgsqlCheckParams, opt) { + if s.PgsqlCheckParams == nil || t.PgsqlCheckParams == nil { + if s.PgsqlCheckParams != nil || t.PgsqlCheckParams != nil { + if opt.NilSameAsEmpty { + empty := &PgsqlCheckParams{} + if s.PgsqlCheckParams == nil { + if !(t.PgsqlCheckParams.Equal(*empty)) { + return false + } + } + if t.PgsqlCheckParams == nil { + if !(s.PgsqlCheckParams.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.PgsqlCheckParams.Equal(*t.PgsqlCheckParams, opt) { return false } @@ -377,7 +647,25 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.Redispatch.Equal(*t.Redispatch, opt) { + if s.Redispatch == nil || t.Redispatch == nil { + if s.Redispatch != nil || t.Redispatch != nil { + if opt.NilSameAsEmpty { + empty := &Redispatch{} + if s.Redispatch == nil { + if !(t.Redispatch.Equal(*empty)) { + return false + } + } + if t.Redispatch == nil { + if !(s.Redispatch.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Redispatch.Equal(*t.Redispatch, opt) { return false } @@ -397,7 +685,25 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.SmtpchkParams.Equal(*t.SmtpchkParams, opt) { + if s.SmtpchkParams == nil || t.SmtpchkParams == nil { + if s.SmtpchkParams != nil || t.SmtpchkParams != nil { + if opt.NilSameAsEmpty { + empty := &SmtpchkParams{} + if s.SmtpchkParams == nil { + if !(t.SmtpchkParams.Equal(*empty)) { + return false + } + } + if t.SmtpchkParams == nil { + if !(s.SmtpchkParams.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.SmtpchkParams.Equal(*t.SmtpchkParams, opt) { return false } @@ -405,7 +711,25 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.Source.Equal(*t.Source, opt) { + if s.Source == nil || t.Source == nil { + if s.Source != nil || t.Source != nil { + if opt.NilSameAsEmpty { + empty := &Source{} + if s.Source == nil { + if !(t.Source.Equal(*empty)) { + return false + } + } + if t.Source == nil { + if !(s.Source.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Source.Equal(*t.Source, opt) { return false } @@ -437,7 +761,25 @@ func (s Defaults) Equal(t Defaults, opts ...Options) bool { return false } - if !s.StatsOptions.Equal(*t.StatsOptions, opt) { + if s.StatsOptions == nil || t.StatsOptions == nil { + if s.StatsOptions != nil || t.StatsOptions != nil { + if opt.NilSameAsEmpty { + empty := &StatsOptions{} + if s.StatsOptions == nil { + if !(t.StatsOptions.Equal(*empty)) { + return false + } + } + if t.StatsOptions == nil { + if !(s.StatsOptions.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.StatsOptions.Equal(*t.StatsOptions, opt) { return false } @@ -555,7 +897,25 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["Backlog"] = []interface{}{ValueOrNil(s.Backlog), ValueOrNil(t.Backlog)} } - if !s.Balance.Equal(*t.Balance, opt) { + if s.Balance == nil || t.Balance == nil { + if s.Balance != nil || t.Balance != nil { + if opt.NilSameAsEmpty { + empty := &Balance{} + if s.Balance == nil { + if !(t.Balance.Equal(*empty)) { + diff["Balance"] = []interface{}{ValueOrNil(s.Balance), ValueOrNil(t.Balance)} + } + } + if t.Balance == nil { + if !(s.Balance.Equal(*empty)) { + diff["Balance"] = []interface{}{ValueOrNil(s.Balance), ValueOrNil(t.Balance)} + } + } + } else { + diff["Balance"] = []interface{}{ValueOrNil(s.Balance), ValueOrNil(t.Balance)} + } + } + } else if !s.Balance.Equal(*t.Balance, opt) { diff["Balance"] = []interface{}{ValueOrNil(s.Balance), ValueOrNil(t.Balance)} } @@ -599,7 +959,25 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["ClitcpkaIntvl"] = []interface{}{ValueOrNil(s.ClitcpkaIntvl), ValueOrNil(t.ClitcpkaIntvl)} } - if !s.Compression.Equal(*t.Compression, opt) { + if s.Compression == nil || t.Compression == nil { + if s.Compression != nil || t.Compression != nil { + if opt.NilSameAsEmpty { + empty := &Compression{} + if s.Compression == nil { + if !(t.Compression.Equal(*empty)) { + diff["Compression"] = []interface{}{ValueOrNil(s.Compression), ValueOrNil(t.Compression)} + } + } + if t.Compression == nil { + if !(s.Compression.Equal(*empty)) { + diff["Compression"] = []interface{}{ValueOrNil(s.Compression), ValueOrNil(t.Compression)} + } + } + } else { + diff["Compression"] = []interface{}{ValueOrNil(s.Compression), ValueOrNil(t.Compression)} + } + } + } else if !s.Compression.Equal(*t.Compression, opt) { diff["Compression"] = []interface{}{ValueOrNil(s.Compression), ValueOrNil(t.Compression)} } @@ -611,7 +989,25 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["Contstats"] = []interface{}{s.Contstats, t.Contstats} } - if !s.Cookie.Equal(*t.Cookie, opt) { + if s.Cookie == nil || t.Cookie == nil { + if s.Cookie != nil || t.Cookie != nil { + if opt.NilSameAsEmpty { + empty := &Cookie{} + if s.Cookie == nil { + if !(t.Cookie.Equal(*empty)) { + diff["Cookie"] = []interface{}{ValueOrNil(s.Cookie), ValueOrNil(t.Cookie)} + } + } + if t.Cookie == nil { + if !(s.Cookie.Equal(*empty)) { + diff["Cookie"] = []interface{}{ValueOrNil(s.Cookie), ValueOrNil(t.Cookie)} + } + } + } else { + diff["Cookie"] = []interface{}{ValueOrNil(s.Cookie), ValueOrNil(t.Cookie)} + } + } + } else if !s.Cookie.Equal(*t.Cookie, opt) { diff["Cookie"] = []interface{}{ValueOrNil(s.Cookie), ValueOrNil(t.Cookie)} } @@ -619,7 +1015,25 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["DefaultBackend"] = []interface{}{s.DefaultBackend, t.DefaultBackend} } - if !s.DefaultServer.Equal(*t.DefaultServer, opt) { + if s.DefaultServer == nil || t.DefaultServer == nil { + if s.DefaultServer != nil || t.DefaultServer != nil { + if opt.NilSameAsEmpty { + empty := &DefaultServer{} + if s.DefaultServer == nil { + if !(t.DefaultServer.Equal(*empty)) { + diff["DefaultServer"] = []interface{}{ValueOrNil(s.DefaultServer), ValueOrNil(t.DefaultServer)} + } + } + if t.DefaultServer == nil { + if !(s.DefaultServer.Equal(*empty)) { + diff["DefaultServer"] = []interface{}{ValueOrNil(s.DefaultServer), ValueOrNil(t.DefaultServer)} + } + } + } else { + diff["DefaultServer"] = []interface{}{ValueOrNil(s.DefaultServer), ValueOrNil(t.DefaultServer)} + } + } + } else if !s.DefaultServer.Equal(*t.DefaultServer, opt) { diff["DefaultServer"] = []interface{}{ValueOrNil(s.DefaultServer), ValueOrNil(t.DefaultServer)} } @@ -643,7 +1057,25 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["DynamicCookieKey"] = []interface{}{s.DynamicCookieKey, t.DynamicCookieKey} } - if !s.EmailAlert.Equal(*t.EmailAlert, opt) { + if s.EmailAlert == nil || t.EmailAlert == nil { + if s.EmailAlert != nil || t.EmailAlert != nil { + if opt.NilSameAsEmpty { + empty := &EmailAlert{} + if s.EmailAlert == nil { + if !(t.EmailAlert.Equal(*empty)) { + diff["EmailAlert"] = []interface{}{ValueOrNil(s.EmailAlert), ValueOrNil(t.EmailAlert)} + } + } + if t.EmailAlert == nil { + if !(s.EmailAlert.Equal(*empty)) { + diff["EmailAlert"] = []interface{}{ValueOrNil(s.EmailAlert), ValueOrNil(t.EmailAlert)} + } + } + } else { + diff["EmailAlert"] = []interface{}{ValueOrNil(s.EmailAlert), ValueOrNil(t.EmailAlert)} + } + } + } else if !s.EmailAlert.Equal(*t.EmailAlert, opt) { diff["EmailAlert"] = []interface{}{ValueOrNil(s.EmailAlert), ValueOrNil(t.EmailAlert)} } @@ -655,11 +1087,47 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["ErrorLogFormat"] = []interface{}{s.ErrorLogFormat, t.ErrorLogFormat} } - if !s.Errorloc302.Equal(*t.Errorloc302, opt) { + if s.Errorloc302 == nil || t.Errorloc302 == nil { + if s.Errorloc302 != nil || t.Errorloc302 != nil { + if opt.NilSameAsEmpty { + empty := &Errorloc{} + if s.Errorloc302 == nil { + if !(t.Errorloc302.Equal(*empty)) { + diff["Errorloc302"] = []interface{}{ValueOrNil(s.Errorloc302), ValueOrNil(t.Errorloc302)} + } + } + if t.Errorloc302 == nil { + if !(s.Errorloc302.Equal(*empty)) { + diff["Errorloc302"] = []interface{}{ValueOrNil(s.Errorloc302), ValueOrNil(t.Errorloc302)} + } + } + } else { + diff["Errorloc302"] = []interface{}{ValueOrNil(s.Errorloc302), ValueOrNil(t.Errorloc302)} + } + } + } else if !s.Errorloc302.Equal(*t.Errorloc302, opt) { diff["Errorloc302"] = []interface{}{ValueOrNil(s.Errorloc302), ValueOrNil(t.Errorloc302)} } - if !s.Errorloc303.Equal(*t.Errorloc303, opt) { + if s.Errorloc303 == nil || t.Errorloc303 == nil { + if s.Errorloc303 != nil || t.Errorloc303 != nil { + if opt.NilSameAsEmpty { + empty := &Errorloc{} + if s.Errorloc303 == nil { + if !(t.Errorloc303.Equal(*empty)) { + diff["Errorloc303"] = []interface{}{ValueOrNil(s.Errorloc303), ValueOrNil(t.Errorloc303)} + } + } + if t.Errorloc303 == nil { + if !(s.Errorloc303.Equal(*empty)) { + diff["Errorloc303"] = []interface{}{ValueOrNil(s.Errorloc303), ValueOrNil(t.Errorloc303)} + } + } + } else { + diff["Errorloc303"] = []interface{}{ValueOrNil(s.Errorloc303), ValueOrNil(t.Errorloc303)} + } + } + } else if !s.Errorloc303.Equal(*t.Errorloc303, opt) { diff["Errorloc303"] = []interface{}{ValueOrNil(s.Errorloc303), ValueOrNil(t.Errorloc303)} } @@ -675,7 +1143,25 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["ExternalCheckPath"] = []interface{}{s.ExternalCheckPath, t.ExternalCheckPath} } - if !s.Forwardfor.Equal(*t.Forwardfor, opt) { + if s.Forwardfor == nil || t.Forwardfor == nil { + if s.Forwardfor != nil || t.Forwardfor != nil { + if opt.NilSameAsEmpty { + empty := &Forwardfor{} + if s.Forwardfor == nil { + if !(t.Forwardfor.Equal(*empty)) { + diff["Forwardfor"] = []interface{}{ValueOrNil(s.Forwardfor), ValueOrNil(t.Forwardfor)} + } + } + if t.Forwardfor == nil { + if !(s.Forwardfor.Equal(*empty)) { + diff["Forwardfor"] = []interface{}{ValueOrNil(s.Forwardfor), ValueOrNil(t.Forwardfor)} + } + } + } else { + diff["Forwardfor"] = []interface{}{ValueOrNil(s.Forwardfor), ValueOrNil(t.Forwardfor)} + } + } + } else if !s.Forwardfor.Equal(*t.Forwardfor, opt) { diff["Forwardfor"] = []interface{}{ValueOrNil(s.Forwardfor), ValueOrNil(t.Forwardfor)} } @@ -695,7 +1181,25 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["H1CaseAdjustBogusServer"] = []interface{}{s.H1CaseAdjustBogusServer, t.H1CaseAdjustBogusServer} } - if !s.HashType.Equal(*t.HashType, opt) { + if s.HashType == nil || t.HashType == nil { + if s.HashType != nil || t.HashType != nil { + if opt.NilSameAsEmpty { + empty := &HashType{} + if s.HashType == nil { + if !(t.HashType.Equal(*empty)) { + diff["HashType"] = []interface{}{ValueOrNil(s.HashType), ValueOrNil(t.HashType)} + } + } + if t.HashType == nil { + if !(s.HashType.Equal(*empty)) { + diff["HashType"] = []interface{}{ValueOrNil(s.HashType), ValueOrNil(t.HashType)} + } + } + } else { + diff["HashType"] = []interface{}{ValueOrNil(s.HashType), ValueOrNil(t.HashType)} + } + } + } else if !s.HashType.Equal(*t.HashType, opt) { diff["HashType"] = []interface{}{ValueOrNil(s.HashType), ValueOrNil(t.HashType)} } @@ -703,7 +1207,25 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["HTTPBufferRequest"] = []interface{}{s.HTTPBufferRequest, t.HTTPBufferRequest} } - if !s.HTTPCheck.Equal(*t.HTTPCheck, opt) { + if s.HTTPCheck == nil || t.HTTPCheck == nil { + if s.HTTPCheck != nil || t.HTTPCheck != nil { + if opt.NilSameAsEmpty { + empty := &HTTPCheck{} + if s.HTTPCheck == nil { + if !(t.HTTPCheck.Equal(*empty)) { + diff["HTTPCheck"] = []interface{}{ValueOrNil(s.HTTPCheck), ValueOrNil(t.HTTPCheck)} + } + } + if t.HTTPCheck == nil { + if !(s.HTTPCheck.Equal(*empty)) { + diff["HTTPCheck"] = []interface{}{ValueOrNil(s.HTTPCheck), ValueOrNil(t.HTTPCheck)} + } + } + } else { + diff["HTTPCheck"] = []interface{}{ValueOrNil(s.HTTPCheck), ValueOrNil(t.HTTPCheck)} + } + } + } else if !s.HTTPCheck.Equal(*t.HTTPCheck, opt) { diff["HTTPCheck"] = []interface{}{ValueOrNil(s.HTTPCheck), ValueOrNil(t.HTTPCheck)} } @@ -751,7 +1273,25 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["HTTPUseProxyHeader"] = []interface{}{s.HTTPUseProxyHeader, t.HTTPUseProxyHeader} } - if !s.HttpchkParams.Equal(*t.HttpchkParams, opt) { + if s.HttpchkParams == nil || t.HttpchkParams == nil { + if s.HttpchkParams != nil || t.HttpchkParams != nil { + if opt.NilSameAsEmpty { + empty := &HttpchkParams{} + if s.HttpchkParams == nil { + if !(t.HttpchkParams.Equal(*empty)) { + diff["HttpchkParams"] = []interface{}{ValueOrNil(s.HttpchkParams), ValueOrNil(t.HttpchkParams)} + } + } + if t.HttpchkParams == nil { + if !(s.HttpchkParams.Equal(*empty)) { + diff["HttpchkParams"] = []interface{}{ValueOrNil(s.HttpchkParams), ValueOrNil(t.HttpchkParams)} + } + } + } else { + diff["HttpchkParams"] = []interface{}{ValueOrNil(s.HttpchkParams), ValueOrNil(t.HttpchkParams)} + } + } + } else if !s.HttpchkParams.Equal(*t.HttpchkParams, opt) { diff["HttpchkParams"] = []interface{}{ValueOrNil(s.HttpchkParams), ValueOrNil(t.HttpchkParams)} } @@ -815,7 +1355,25 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["MonitorURI"] = []interface{}{s.MonitorURI, t.MonitorURI} } - if !s.MysqlCheckParams.Equal(*t.MysqlCheckParams, opt) { + if s.MysqlCheckParams == nil || t.MysqlCheckParams == nil { + if s.MysqlCheckParams != nil || t.MysqlCheckParams != nil { + if opt.NilSameAsEmpty { + empty := &MysqlCheckParams{} + if s.MysqlCheckParams == nil { + if !(t.MysqlCheckParams.Equal(*empty)) { + diff["MysqlCheckParams"] = []interface{}{ValueOrNil(s.MysqlCheckParams), ValueOrNil(t.MysqlCheckParams)} + } + } + if t.MysqlCheckParams == nil { + if !(s.MysqlCheckParams.Equal(*empty)) { + diff["MysqlCheckParams"] = []interface{}{ValueOrNil(s.MysqlCheckParams), ValueOrNil(t.MysqlCheckParams)} + } + } + } else { + diff["MysqlCheckParams"] = []interface{}{ValueOrNil(s.MysqlCheckParams), ValueOrNil(t.MysqlCheckParams)} + } + } + } else if !s.MysqlCheckParams.Equal(*t.MysqlCheckParams, opt) { diff["MysqlCheckParams"] = []interface{}{ValueOrNil(s.MysqlCheckParams), ValueOrNil(t.MysqlCheckParams)} } @@ -827,7 +1385,25 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["Nolinger"] = []interface{}{s.Nolinger, t.Nolinger} } - if !s.Originalto.Equal(*t.Originalto, opt) { + if s.Originalto == nil || t.Originalto == nil { + if s.Originalto != nil || t.Originalto != nil { + if opt.NilSameAsEmpty { + empty := &Originalto{} + if s.Originalto == nil { + if !(t.Originalto.Equal(*empty)) { + diff["Originalto"] = []interface{}{ValueOrNil(s.Originalto), ValueOrNil(t.Originalto)} + } + } + if t.Originalto == nil { + if !(s.Originalto.Equal(*empty)) { + diff["Originalto"] = []interface{}{ValueOrNil(s.Originalto), ValueOrNil(t.Originalto)} + } + } + } else { + diff["Originalto"] = []interface{}{ValueOrNil(s.Originalto), ValueOrNil(t.Originalto)} + } + } + } else if !s.Originalto.Equal(*t.Originalto, opt) { diff["Originalto"] = []interface{}{ValueOrNil(s.Originalto), ValueOrNil(t.Originalto)} } @@ -835,11 +1411,47 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["Persist"] = []interface{}{s.Persist, t.Persist} } - if !s.PersistRule.Equal(*t.PersistRule, opt) { + if s.PersistRule == nil || t.PersistRule == nil { + if s.PersistRule != nil || t.PersistRule != nil { + if opt.NilSameAsEmpty { + empty := &PersistRule{} + if s.PersistRule == nil { + if !(t.PersistRule.Equal(*empty)) { + diff["PersistRule"] = []interface{}{ValueOrNil(s.PersistRule), ValueOrNil(t.PersistRule)} + } + } + if t.PersistRule == nil { + if !(s.PersistRule.Equal(*empty)) { + diff["PersistRule"] = []interface{}{ValueOrNil(s.PersistRule), ValueOrNil(t.PersistRule)} + } + } + } else { + diff["PersistRule"] = []interface{}{ValueOrNil(s.PersistRule), ValueOrNil(t.PersistRule)} + } + } + } else if !s.PersistRule.Equal(*t.PersistRule, opt) { diff["PersistRule"] = []interface{}{ValueOrNil(s.PersistRule), ValueOrNil(t.PersistRule)} } - if !s.PgsqlCheckParams.Equal(*t.PgsqlCheckParams, opt) { + if s.PgsqlCheckParams == nil || t.PgsqlCheckParams == nil { + if s.PgsqlCheckParams != nil || t.PgsqlCheckParams != nil { + if opt.NilSameAsEmpty { + empty := &PgsqlCheckParams{} + if s.PgsqlCheckParams == nil { + if !(t.PgsqlCheckParams.Equal(*empty)) { + diff["PgsqlCheckParams"] = []interface{}{ValueOrNil(s.PgsqlCheckParams), ValueOrNil(t.PgsqlCheckParams)} + } + } + if t.PgsqlCheckParams == nil { + if !(s.PgsqlCheckParams.Equal(*empty)) { + diff["PgsqlCheckParams"] = []interface{}{ValueOrNil(s.PgsqlCheckParams), ValueOrNil(t.PgsqlCheckParams)} + } + } + } else { + diff["PgsqlCheckParams"] = []interface{}{ValueOrNil(s.PgsqlCheckParams), ValueOrNil(t.PgsqlCheckParams)} + } + } + } else if !s.PgsqlCheckParams.Equal(*t.PgsqlCheckParams, opt) { diff["PgsqlCheckParams"] = []interface{}{ValueOrNil(s.PgsqlCheckParams), ValueOrNil(t.PgsqlCheckParams)} } @@ -851,7 +1463,25 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["QueueTimeout"] = []interface{}{ValueOrNil(s.QueueTimeout), ValueOrNil(t.QueueTimeout)} } - if !s.Redispatch.Equal(*t.Redispatch, opt) { + if s.Redispatch == nil || t.Redispatch == nil { + if s.Redispatch != nil || t.Redispatch != nil { + if opt.NilSameAsEmpty { + empty := &Redispatch{} + if s.Redispatch == nil { + if !(t.Redispatch.Equal(*empty)) { + diff["Redispatch"] = []interface{}{ValueOrNil(s.Redispatch), ValueOrNil(t.Redispatch)} + } + } + if t.Redispatch == nil { + if !(s.Redispatch.Equal(*empty)) { + diff["Redispatch"] = []interface{}{ValueOrNil(s.Redispatch), ValueOrNil(t.Redispatch)} + } + } + } else { + diff["Redispatch"] = []interface{}{ValueOrNil(s.Redispatch), ValueOrNil(t.Redispatch)} + } + } + } else if !s.Redispatch.Equal(*t.Redispatch, opt) { diff["Redispatch"] = []interface{}{ValueOrNil(s.Redispatch), ValueOrNil(t.Redispatch)} } @@ -871,7 +1501,25 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["ServerTimeout"] = []interface{}{ValueOrNil(s.ServerTimeout), ValueOrNil(t.ServerTimeout)} } - if !s.SmtpchkParams.Equal(*t.SmtpchkParams, opt) { + if s.SmtpchkParams == nil || t.SmtpchkParams == nil { + if s.SmtpchkParams != nil || t.SmtpchkParams != nil { + if opt.NilSameAsEmpty { + empty := &SmtpchkParams{} + if s.SmtpchkParams == nil { + if !(t.SmtpchkParams.Equal(*empty)) { + diff["SmtpchkParams"] = []interface{}{ValueOrNil(s.SmtpchkParams), ValueOrNil(t.SmtpchkParams)} + } + } + if t.SmtpchkParams == nil { + if !(s.SmtpchkParams.Equal(*empty)) { + diff["SmtpchkParams"] = []interface{}{ValueOrNil(s.SmtpchkParams), ValueOrNil(t.SmtpchkParams)} + } + } + } else { + diff["SmtpchkParams"] = []interface{}{ValueOrNil(s.SmtpchkParams), ValueOrNil(t.SmtpchkParams)} + } + } + } else if !s.SmtpchkParams.Equal(*t.SmtpchkParams, opt) { diff["SmtpchkParams"] = []interface{}{ValueOrNil(s.SmtpchkParams), ValueOrNil(t.SmtpchkParams)} } @@ -879,7 +1527,25 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["SocketStats"] = []interface{}{s.SocketStats, t.SocketStats} } - if !s.Source.Equal(*t.Source, opt) { + if s.Source == nil || t.Source == nil { + if s.Source != nil || t.Source != nil { + if opt.NilSameAsEmpty { + empty := &Source{} + if s.Source == nil { + if !(t.Source.Equal(*empty)) { + diff["Source"] = []interface{}{ValueOrNil(s.Source), ValueOrNil(t.Source)} + } + } + if t.Source == nil { + if !(s.Source.Equal(*empty)) { + diff["Source"] = []interface{}{ValueOrNil(s.Source), ValueOrNil(t.Source)} + } + } + } else { + diff["Source"] = []interface{}{ValueOrNil(s.Source), ValueOrNil(t.Source)} + } + } + } else if !s.Source.Equal(*t.Source, opt) { diff["Source"] = []interface{}{ValueOrNil(s.Source), ValueOrNil(t.Source)} } @@ -911,7 +1577,25 @@ func (s Defaults) Diff(t Defaults, opts ...Options) map[string][]interface{} { diff["SrvtcpkaIntvl"] = []interface{}{ValueOrNil(s.SrvtcpkaIntvl), ValueOrNil(t.SrvtcpkaIntvl)} } - if !s.StatsOptions.Equal(*t.StatsOptions, opt) { + if s.StatsOptions == nil || t.StatsOptions == nil { + if s.StatsOptions != nil || t.StatsOptions != nil { + if opt.NilSameAsEmpty { + empty := &StatsOptions{} + if s.StatsOptions == nil { + if !(t.StatsOptions.Equal(*empty)) { + diff["StatsOptions"] = []interface{}{ValueOrNil(s.StatsOptions), ValueOrNil(t.StatsOptions)} + } + } + if t.StatsOptions == nil { + if !(s.StatsOptions.Equal(*empty)) { + diff["StatsOptions"] = []interface{}{ValueOrNil(s.StatsOptions), ValueOrNil(t.StatsOptions)} + } + } + } else { + diff["StatsOptions"] = []interface{}{ValueOrNil(s.StatsOptions), ValueOrNil(t.StatsOptions)} + } + } + } else if !s.StatsOptions.Equal(*t.StatsOptions, opt) { diff["StatsOptions"] = []interface{}{ValueOrNil(s.StatsOptions), ValueOrNil(t.StatsOptions)} } diff --git a/models/fcgi_log_stderr_compare.go b/models/fcgi_log_stderr_compare.go index ac312547..1ed09f5b 100644 --- a/models/fcgi_log_stderr_compare.go +++ b/models/fcgi_log_stderr_compare.go @@ -61,7 +61,25 @@ func (s FCGILogStderr) Equal(t FCGILogStderr, opts ...Options) bool { return false } - if !s.Sample.Equal(*t.Sample, opt) { + if s.Sample == nil || t.Sample == nil { + if s.Sample != nil || t.Sample != nil { + if opt.NilSameAsEmpty { + empty := &FCGILogStderrSample{} + if s.Sample == nil { + if !(t.Sample.Equal(*empty)) { + return false + } + } + if t.Sample == nil { + if !(s.Sample.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Sample.Equal(*t.Sample, opt) { return false } @@ -113,7 +131,25 @@ func (s FCGILogStderr) Diff(t FCGILogStderr, opts ...Options) map[string][]inter diff["Minlevel"] = []interface{}{s.Minlevel, t.Minlevel} } - if !s.Sample.Equal(*t.Sample, opt) { + if s.Sample == nil || t.Sample == nil { + if s.Sample != nil || t.Sample != nil { + if opt.NilSameAsEmpty { + empty := &FCGILogStderrSample{} + if s.Sample == nil { + if !(t.Sample.Equal(*empty)) { + diff["Sample"] = []interface{}{ValueOrNil(s.Sample), ValueOrNil(t.Sample)} + } + } + if t.Sample == nil { + if !(s.Sample.Equal(*empty)) { + diff["Sample"] = []interface{}{ValueOrNil(s.Sample), ValueOrNil(t.Sample)} + } + } + } else { + diff["Sample"] = []interface{}{ValueOrNil(s.Sample), ValueOrNil(t.Sample)} + } + } + } else if !s.Sample.Equal(*t.Sample, opt) { diff["Sample"] = []interface{}{ValueOrNil(s.Sample), ValueOrNil(t.Sample)} } diff --git a/models/frontend_compare.go b/models/frontend_compare.go index 3682c1e9..de5d989e 100644 --- a/models/frontend_compare.go +++ b/models/frontend_compare.go @@ -97,7 +97,25 @@ func (s Frontend) Equal(t Frontend, opts ...Options) bool { return false } - if !s.Compression.Equal(*t.Compression, opt) { + if s.Compression == nil || t.Compression == nil { + if s.Compression != nil || t.Compression != nil { + if opt.NilSameAsEmpty { + empty := &Compression{} + if s.Compression == nil { + if !(t.Compression.Equal(*empty)) { + return false + } + } + if t.Compression == nil { + if !(s.Compression.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Compression.Equal(*t.Compression, opt) { return false } @@ -129,7 +147,25 @@ func (s Frontend) Equal(t Frontend, opts ...Options) bool { return false } - if !s.EmailAlert.Equal(*t.EmailAlert, opt) { + if s.EmailAlert == nil || t.EmailAlert == nil { + if s.EmailAlert != nil || t.EmailAlert != nil { + if opt.NilSameAsEmpty { + empty := &EmailAlert{} + if s.EmailAlert == nil { + if !(t.EmailAlert.Equal(*empty)) { + return false + } + } + if t.EmailAlert == nil { + if !(s.EmailAlert.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.EmailAlert.Equal(*t.EmailAlert, opt) { return false } @@ -141,15 +177,69 @@ func (s Frontend) Equal(t Frontend, opts ...Options) bool { return false } - if !s.Errorloc302.Equal(*t.Errorloc302, opt) { + if s.Errorloc302 == nil || t.Errorloc302 == nil { + if s.Errorloc302 != nil || t.Errorloc302 != nil { + if opt.NilSameAsEmpty { + empty := &Errorloc{} + if s.Errorloc302 == nil { + if !(t.Errorloc302.Equal(*empty)) { + return false + } + } + if t.Errorloc302 == nil { + if !(s.Errorloc302.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Errorloc302.Equal(*t.Errorloc302, opt) { return false } - if !s.Errorloc303.Equal(*t.Errorloc303, opt) { + if s.Errorloc303 == nil || t.Errorloc303 == nil { + if s.Errorloc303 != nil || t.Errorloc303 != nil { + if opt.NilSameAsEmpty { + empty := &Errorloc{} + if s.Errorloc303 == nil { + if !(t.Errorloc303.Equal(*empty)) { + return false + } + } + if t.Errorloc303 == nil { + if !(s.Errorloc303.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Errorloc303.Equal(*t.Errorloc303, opt) { return false } - if !s.Forwardfor.Equal(*t.Forwardfor, opt) { + if s.Forwardfor == nil || t.Forwardfor == nil { + if s.Forwardfor != nil || t.Forwardfor != nil { + if opt.NilSameAsEmpty { + empty := &Forwardfor{} + if s.Forwardfor == nil { + if !(t.Forwardfor.Equal(*empty)) { + return false + } + } + if t.Forwardfor == nil { + if !(s.Forwardfor.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Forwardfor.Equal(*t.Forwardfor, opt) { return false } @@ -245,7 +335,25 @@ func (s Frontend) Equal(t Frontend, opts ...Options) bool { return false } - if !s.MonitorFail.Equal(*t.MonitorFail, opt) { + if s.MonitorFail == nil || t.MonitorFail == nil { + if s.MonitorFail != nil || t.MonitorFail != nil { + if opt.NilSameAsEmpty { + empty := &MonitorFail{} + if s.MonitorFail == nil { + if !(t.MonitorFail.Equal(*empty)) { + return false + } + } + if t.MonitorFail == nil { + if !(s.MonitorFail.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.MonitorFail.Equal(*t.MonitorFail, opt) { return false } @@ -261,7 +369,25 @@ func (s Frontend) Equal(t Frontend, opts ...Options) bool { return false } - if !s.Originalto.Equal(*t.Originalto, opt) { + if s.Originalto == nil || t.Originalto == nil { + if s.Originalto != nil || t.Originalto != nil { + if opt.NilSameAsEmpty { + empty := &Originalto{} + if s.Originalto == nil { + if !(t.Originalto.Equal(*empty)) { + return false + } + } + if t.Originalto == nil { + if !(s.Originalto.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Originalto.Equal(*t.Originalto, opt) { return false } @@ -281,11 +407,47 @@ func (s Frontend) Equal(t Frontend, opts ...Options) bool { return false } - if !s.StatsOptions.Equal(*t.StatsOptions, opt) { + if s.StatsOptions == nil || t.StatsOptions == nil { + if s.StatsOptions != nil || t.StatsOptions != nil { + if opt.NilSameAsEmpty { + empty := &StatsOptions{} + if s.StatsOptions == nil { + if !(t.StatsOptions.Equal(*empty)) { + return false + } + } + if t.StatsOptions == nil { + if !(s.StatsOptions.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.StatsOptions.Equal(*t.StatsOptions, opt) { return false } - if !s.StickTable.Equal(*t.StickTable, opt) { + if s.StickTable == nil || t.StickTable == nil { + if s.StickTable != nil || t.StickTable != nil { + if opt.NilSameAsEmpty { + empty := &ConfigStickTable{} + if s.StickTable == nil { + if !(t.StickTable.Equal(*empty)) { + return false + } + } + if t.StickTable == nil { + if !(s.StickTable.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.StickTable.Equal(*t.StickTable, opt) { return false } @@ -407,7 +569,25 @@ func (s Frontend) Diff(t Frontend, opts ...Options) map[string][]interface{} { diff["ClitcpkaIntvl"] = []interface{}{ValueOrNil(s.ClitcpkaIntvl), ValueOrNil(t.ClitcpkaIntvl)} } - if !s.Compression.Equal(*t.Compression, opt) { + if s.Compression == nil || t.Compression == nil { + if s.Compression != nil || t.Compression != nil { + if opt.NilSameAsEmpty { + empty := &Compression{} + if s.Compression == nil { + if !(t.Compression.Equal(*empty)) { + diff["Compression"] = []interface{}{ValueOrNil(s.Compression), ValueOrNil(t.Compression)} + } + } + if t.Compression == nil { + if !(s.Compression.Equal(*empty)) { + diff["Compression"] = []interface{}{ValueOrNil(s.Compression), ValueOrNil(t.Compression)} + } + } + } else { + diff["Compression"] = []interface{}{ValueOrNil(s.Compression), ValueOrNil(t.Compression)} + } + } + } else if !s.Compression.Equal(*t.Compression, opt) { diff["Compression"] = []interface{}{ValueOrNil(s.Compression), ValueOrNil(t.Compression)} } @@ -439,7 +619,25 @@ func (s Frontend) Diff(t Frontend, opts ...Options) map[string][]interface{} { diff["Dontlognull"] = []interface{}{s.Dontlognull, t.Dontlognull} } - if !s.EmailAlert.Equal(*t.EmailAlert, opt) { + if s.EmailAlert == nil || t.EmailAlert == nil { + if s.EmailAlert != nil || t.EmailAlert != nil { + if opt.NilSameAsEmpty { + empty := &EmailAlert{} + if s.EmailAlert == nil { + if !(t.EmailAlert.Equal(*empty)) { + diff["EmailAlert"] = []interface{}{ValueOrNil(s.EmailAlert), ValueOrNil(t.EmailAlert)} + } + } + if t.EmailAlert == nil { + if !(s.EmailAlert.Equal(*empty)) { + diff["EmailAlert"] = []interface{}{ValueOrNil(s.EmailAlert), ValueOrNil(t.EmailAlert)} + } + } + } else { + diff["EmailAlert"] = []interface{}{ValueOrNil(s.EmailAlert), ValueOrNil(t.EmailAlert)} + } + } + } else if !s.EmailAlert.Equal(*t.EmailAlert, opt) { diff["EmailAlert"] = []interface{}{ValueOrNil(s.EmailAlert), ValueOrNil(t.EmailAlert)} } @@ -451,15 +649,69 @@ func (s Frontend) Diff(t Frontend, opts ...Options) map[string][]interface{} { diff["ErrorLogFormat"] = []interface{}{s.ErrorLogFormat, t.ErrorLogFormat} } - if !s.Errorloc302.Equal(*t.Errorloc302, opt) { + if s.Errorloc302 == nil || t.Errorloc302 == nil { + if s.Errorloc302 != nil || t.Errorloc302 != nil { + if opt.NilSameAsEmpty { + empty := &Errorloc{} + if s.Errorloc302 == nil { + if !(t.Errorloc302.Equal(*empty)) { + diff["Errorloc302"] = []interface{}{ValueOrNil(s.Errorloc302), ValueOrNil(t.Errorloc302)} + } + } + if t.Errorloc302 == nil { + if !(s.Errorloc302.Equal(*empty)) { + diff["Errorloc302"] = []interface{}{ValueOrNil(s.Errorloc302), ValueOrNil(t.Errorloc302)} + } + } + } else { + diff["Errorloc302"] = []interface{}{ValueOrNil(s.Errorloc302), ValueOrNil(t.Errorloc302)} + } + } + } else if !s.Errorloc302.Equal(*t.Errorloc302, opt) { diff["Errorloc302"] = []interface{}{ValueOrNil(s.Errorloc302), ValueOrNil(t.Errorloc302)} } - if !s.Errorloc303.Equal(*t.Errorloc303, opt) { + if s.Errorloc303 == nil || t.Errorloc303 == nil { + if s.Errorloc303 != nil || t.Errorloc303 != nil { + if opt.NilSameAsEmpty { + empty := &Errorloc{} + if s.Errorloc303 == nil { + if !(t.Errorloc303.Equal(*empty)) { + diff["Errorloc303"] = []interface{}{ValueOrNil(s.Errorloc303), ValueOrNil(t.Errorloc303)} + } + } + if t.Errorloc303 == nil { + if !(s.Errorloc303.Equal(*empty)) { + diff["Errorloc303"] = []interface{}{ValueOrNil(s.Errorloc303), ValueOrNil(t.Errorloc303)} + } + } + } else { + diff["Errorloc303"] = []interface{}{ValueOrNil(s.Errorloc303), ValueOrNil(t.Errorloc303)} + } + } + } else if !s.Errorloc303.Equal(*t.Errorloc303, opt) { diff["Errorloc303"] = []interface{}{ValueOrNil(s.Errorloc303), ValueOrNil(t.Errorloc303)} } - if !s.Forwardfor.Equal(*t.Forwardfor, opt) { + if s.Forwardfor == nil || t.Forwardfor == nil { + if s.Forwardfor != nil || t.Forwardfor != nil { + if opt.NilSameAsEmpty { + empty := &Forwardfor{} + if s.Forwardfor == nil { + if !(t.Forwardfor.Equal(*empty)) { + diff["Forwardfor"] = []interface{}{ValueOrNil(s.Forwardfor), ValueOrNil(t.Forwardfor)} + } + } + if t.Forwardfor == nil { + if !(s.Forwardfor.Equal(*empty)) { + diff["Forwardfor"] = []interface{}{ValueOrNil(s.Forwardfor), ValueOrNil(t.Forwardfor)} + } + } + } else { + diff["Forwardfor"] = []interface{}{ValueOrNil(s.Forwardfor), ValueOrNil(t.Forwardfor)} + } + } + } else if !s.Forwardfor.Equal(*t.Forwardfor, opt) { diff["Forwardfor"] = []interface{}{ValueOrNil(s.Forwardfor), ValueOrNil(t.Forwardfor)} } @@ -555,7 +807,25 @@ func (s Frontend) Diff(t Frontend, opts ...Options) map[string][]interface{} { diff["Mode"] = []interface{}{s.Mode, t.Mode} } - if !s.MonitorFail.Equal(*t.MonitorFail, opt) { + if s.MonitorFail == nil || t.MonitorFail == nil { + if s.MonitorFail != nil || t.MonitorFail != nil { + if opt.NilSameAsEmpty { + empty := &MonitorFail{} + if s.MonitorFail == nil { + if !(t.MonitorFail.Equal(*empty)) { + diff["MonitorFail"] = []interface{}{ValueOrNil(s.MonitorFail), ValueOrNil(t.MonitorFail)} + } + } + if t.MonitorFail == nil { + if !(s.MonitorFail.Equal(*empty)) { + diff["MonitorFail"] = []interface{}{ValueOrNil(s.MonitorFail), ValueOrNil(t.MonitorFail)} + } + } + } else { + diff["MonitorFail"] = []interface{}{ValueOrNil(s.MonitorFail), ValueOrNil(t.MonitorFail)} + } + } + } else if !s.MonitorFail.Equal(*t.MonitorFail, opt) { diff["MonitorFail"] = []interface{}{ValueOrNil(s.MonitorFail), ValueOrNil(t.MonitorFail)} } @@ -571,7 +841,25 @@ func (s Frontend) Diff(t Frontend, opts ...Options) map[string][]interface{} { diff["Nolinger"] = []interface{}{s.Nolinger, t.Nolinger} } - if !s.Originalto.Equal(*t.Originalto, opt) { + if s.Originalto == nil || t.Originalto == nil { + if s.Originalto != nil || t.Originalto != nil { + if opt.NilSameAsEmpty { + empty := &Originalto{} + if s.Originalto == nil { + if !(t.Originalto.Equal(*empty)) { + diff["Originalto"] = []interface{}{ValueOrNil(s.Originalto), ValueOrNil(t.Originalto)} + } + } + if t.Originalto == nil { + if !(s.Originalto.Equal(*empty)) { + diff["Originalto"] = []interface{}{ValueOrNil(s.Originalto), ValueOrNil(t.Originalto)} + } + } + } else { + diff["Originalto"] = []interface{}{ValueOrNil(s.Originalto), ValueOrNil(t.Originalto)} + } + } + } else if !s.Originalto.Equal(*t.Originalto, opt) { diff["Originalto"] = []interface{}{ValueOrNil(s.Originalto), ValueOrNil(t.Originalto)} } @@ -591,11 +879,47 @@ func (s Frontend) Diff(t Frontend, opts ...Options) map[string][]interface{} { diff["SpliceResponse"] = []interface{}{s.SpliceResponse, t.SpliceResponse} } - if !s.StatsOptions.Equal(*t.StatsOptions, opt) { + if s.StatsOptions == nil || t.StatsOptions == nil { + if s.StatsOptions != nil || t.StatsOptions != nil { + if opt.NilSameAsEmpty { + empty := &StatsOptions{} + if s.StatsOptions == nil { + if !(t.StatsOptions.Equal(*empty)) { + diff["StatsOptions"] = []interface{}{ValueOrNil(s.StatsOptions), ValueOrNil(t.StatsOptions)} + } + } + if t.StatsOptions == nil { + if !(s.StatsOptions.Equal(*empty)) { + diff["StatsOptions"] = []interface{}{ValueOrNil(s.StatsOptions), ValueOrNil(t.StatsOptions)} + } + } + } else { + diff["StatsOptions"] = []interface{}{ValueOrNil(s.StatsOptions), ValueOrNil(t.StatsOptions)} + } + } + } else if !s.StatsOptions.Equal(*t.StatsOptions, opt) { diff["StatsOptions"] = []interface{}{ValueOrNil(s.StatsOptions), ValueOrNil(t.StatsOptions)} } - if !s.StickTable.Equal(*t.StickTable, opt) { + if s.StickTable == nil || t.StickTable == nil { + if s.StickTable != nil || t.StickTable != nil { + if opt.NilSameAsEmpty { + empty := &ConfigStickTable{} + if s.StickTable == nil { + if !(t.StickTable.Equal(*empty)) { + diff["StickTable"] = []interface{}{ValueOrNil(s.StickTable), ValueOrNil(t.StickTable)} + } + } + if t.StickTable == nil { + if !(s.StickTable.Equal(*empty)) { + diff["StickTable"] = []interface{}{ValueOrNil(s.StickTable), ValueOrNil(t.StickTable)} + } + } + } else { + diff["StickTable"] = []interface{}{ValueOrNil(s.StickTable), ValueOrNil(t.StickTable)} + } + } + } else if !s.StickTable.Equal(*t.StickTable, opt) { diff["StickTable"] = []interface{}{ValueOrNil(s.StickTable), ValueOrNil(t.StickTable)} } diff --git a/models/global_compare.go b/models/global_compare.go index cadc3a37..f382f664 100644 --- a/models/global_compare.go +++ b/models/global_compare.go @@ -159,7 +159,25 @@ func (s Global) Equal(t Global, opts ...Options) bool { return false } - if !s.DefaultPath.Equal(*t.DefaultPath, opt) { + if s.DefaultPath == nil || t.DefaultPath == nil { + if s.DefaultPath != nil || t.DefaultPath != nil { + if opt.NilSameAsEmpty { + empty := &GlobalDefaultPath{} + if s.DefaultPath == nil { + if !(t.DefaultPath.Equal(*empty)) { + return false + } + } + if t.DefaultPath == nil { + if !(s.DefaultPath.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.DefaultPath.Equal(*t.DefaultPath, opt) { return false } @@ -167,7 +185,25 @@ func (s Global) Equal(t Global, opts ...Options) bool { return false } - if !s.DeviceAtlasOptions.Equal(*t.DeviceAtlasOptions, opt) { + if s.DeviceAtlasOptions == nil || t.DeviceAtlasOptions == nil { + if s.DeviceAtlasOptions != nil || t.DeviceAtlasOptions != nil { + if opt.NilSameAsEmpty { + empty := &GlobalDeviceAtlasOptions{} + if s.DeviceAtlasOptions == nil { + if !(t.DeviceAtlasOptions.Equal(*empty)) { + return false + } + } + if t.DeviceAtlasOptions == nil { + if !(s.DeviceAtlasOptions.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.DeviceAtlasOptions.Equal(*t.DeviceAtlasOptions, opt) { return false } @@ -179,7 +215,25 @@ func (s Global) Equal(t Global, opts ...Options) bool { return false } - if !s.FiftyOneDegreesOptions.Equal(*t.FiftyOneDegreesOptions, opt) { + if s.FiftyOneDegreesOptions == nil || t.FiftyOneDegreesOptions == nil { + if s.FiftyOneDegreesOptions != nil || t.FiftyOneDegreesOptions != nil { + if opt.NilSameAsEmpty { + empty := &GlobalFiftyOneDegreesOptions{} + if s.FiftyOneDegreesOptions == nil { + if !(t.FiftyOneDegreesOptions.Equal(*empty)) { + return false + } + } + if t.FiftyOneDegreesOptions == nil { + if !(s.FiftyOneDegreesOptions.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.FiftyOneDegreesOptions.Equal(*t.FiftyOneDegreesOptions, opt) { return false } @@ -259,7 +313,25 @@ func (s Global) Equal(t Global, opts ...Options) bool { return false } - if !s.LogSendHostname.Equal(*t.LogSendHostname, opt) { + if s.LogSendHostname == nil || t.LogSendHostname == nil { + if s.LogSendHostname != nil || t.LogSendHostname != nil { + if opt.NilSameAsEmpty { + empty := &GlobalLogSendHostname{} + if s.LogSendHostname == nil { + if !(t.LogSendHostname.Equal(*empty)) { + return false + } + } + if t.LogSendHostname == nil { + if !(s.LogSendHostname.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.LogSendHostname.Equal(*t.LogSendHostname, opt) { return false } @@ -523,7 +595,25 @@ func (s Global) Equal(t Global, opts ...Options) bool { return false } - if !s.TuneOptions.Equal(*t.TuneOptions, opt) { + if s.TuneOptions == nil || t.TuneOptions == nil { + if s.TuneOptions != nil || t.TuneOptions != nil { + if opt.NilSameAsEmpty { + empty := &GlobalTuneOptions{} + if s.TuneOptions == nil { + if !(t.TuneOptions.Equal(*empty)) { + return false + } + } + if t.TuneOptions == nil { + if !(s.TuneOptions.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.TuneOptions.Equal(*t.TuneOptions, opt) { return false } @@ -547,7 +637,25 @@ func (s Global) Equal(t Global, opts ...Options) bool { return false } - if !s.WurflOptions.Equal(*t.WurflOptions, opt) { + if s.WurflOptions == nil || t.WurflOptions == nil { + if s.WurflOptions != nil || t.WurflOptions != nil { + if opt.NilSameAsEmpty { + empty := &GlobalWurflOptions{} + if s.WurflOptions == nil { + if !(t.WurflOptions.Equal(*empty)) { + return false + } + } + if t.WurflOptions == nil { + if !(s.WurflOptions.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.WurflOptions.Equal(*t.WurflOptions, opt) { return false } @@ -760,7 +868,25 @@ func (s Global) Diff(t Global, opts ...Options) map[string][]interface{} { diff["Daemon"] = []interface{}{s.Daemon, t.Daemon} } - if !s.DefaultPath.Equal(*t.DefaultPath, opt) { + if s.DefaultPath == nil || t.DefaultPath == nil { + if s.DefaultPath != nil || t.DefaultPath != nil { + if opt.NilSameAsEmpty { + empty := &GlobalDefaultPath{} + if s.DefaultPath == nil { + if !(t.DefaultPath.Equal(*empty)) { + diff["DefaultPath"] = []interface{}{ValueOrNil(s.DefaultPath), ValueOrNil(t.DefaultPath)} + } + } + if t.DefaultPath == nil { + if !(s.DefaultPath.Equal(*empty)) { + diff["DefaultPath"] = []interface{}{ValueOrNil(s.DefaultPath), ValueOrNil(t.DefaultPath)} + } + } + } else { + diff["DefaultPath"] = []interface{}{ValueOrNil(s.DefaultPath), ValueOrNil(t.DefaultPath)} + } + } + } else if !s.DefaultPath.Equal(*t.DefaultPath, opt) { diff["DefaultPath"] = []interface{}{ValueOrNil(s.DefaultPath), ValueOrNil(t.DefaultPath)} } @@ -768,7 +894,25 @@ func (s Global) Diff(t Global, opts ...Options) map[string][]interface{} { diff["Description"] = []interface{}{s.Description, t.Description} } - if !s.DeviceAtlasOptions.Equal(*t.DeviceAtlasOptions, opt) { + if s.DeviceAtlasOptions == nil || t.DeviceAtlasOptions == nil { + if s.DeviceAtlasOptions != nil || t.DeviceAtlasOptions != nil { + if opt.NilSameAsEmpty { + empty := &GlobalDeviceAtlasOptions{} + if s.DeviceAtlasOptions == nil { + if !(t.DeviceAtlasOptions.Equal(*empty)) { + diff["DeviceAtlasOptions"] = []interface{}{ValueOrNil(s.DeviceAtlasOptions), ValueOrNil(t.DeviceAtlasOptions)} + } + } + if t.DeviceAtlasOptions == nil { + if !(s.DeviceAtlasOptions.Equal(*empty)) { + diff["DeviceAtlasOptions"] = []interface{}{ValueOrNil(s.DeviceAtlasOptions), ValueOrNil(t.DeviceAtlasOptions)} + } + } + } else { + diff["DeviceAtlasOptions"] = []interface{}{ValueOrNil(s.DeviceAtlasOptions), ValueOrNil(t.DeviceAtlasOptions)} + } + } + } else if !s.DeviceAtlasOptions.Equal(*t.DeviceAtlasOptions, opt) { diff["DeviceAtlasOptions"] = []interface{}{ValueOrNil(s.DeviceAtlasOptions), ValueOrNil(t.DeviceAtlasOptions)} } @@ -780,7 +924,25 @@ func (s Global) Diff(t Global, opts ...Options) map[string][]interface{} { diff["ExternalCheck"] = []interface{}{s.ExternalCheck, t.ExternalCheck} } - if !s.FiftyOneDegreesOptions.Equal(*t.FiftyOneDegreesOptions, opt) { + if s.FiftyOneDegreesOptions == nil || t.FiftyOneDegreesOptions == nil { + if s.FiftyOneDegreesOptions != nil || t.FiftyOneDegreesOptions != nil { + if opt.NilSameAsEmpty { + empty := &GlobalFiftyOneDegreesOptions{} + if s.FiftyOneDegreesOptions == nil { + if !(t.FiftyOneDegreesOptions.Equal(*empty)) { + diff["FiftyOneDegreesOptions"] = []interface{}{ValueOrNil(s.FiftyOneDegreesOptions), ValueOrNil(t.FiftyOneDegreesOptions)} + } + } + if t.FiftyOneDegreesOptions == nil { + if !(s.FiftyOneDegreesOptions.Equal(*empty)) { + diff["FiftyOneDegreesOptions"] = []interface{}{ValueOrNil(s.FiftyOneDegreesOptions), ValueOrNil(t.FiftyOneDegreesOptions)} + } + } + } else { + diff["FiftyOneDegreesOptions"] = []interface{}{ValueOrNil(s.FiftyOneDegreesOptions), ValueOrNil(t.FiftyOneDegreesOptions)} + } + } + } else if !s.FiftyOneDegreesOptions.Equal(*t.FiftyOneDegreesOptions, opt) { diff["FiftyOneDegreesOptions"] = []interface{}{ValueOrNil(s.FiftyOneDegreesOptions), ValueOrNil(t.FiftyOneDegreesOptions)} } @@ -860,7 +1022,25 @@ func (s Global) Diff(t Global, opts ...Options) map[string][]interface{} { diff["Localpeer"] = []interface{}{s.Localpeer, t.Localpeer} } - if !s.LogSendHostname.Equal(*t.LogSendHostname, opt) { + if s.LogSendHostname == nil || t.LogSendHostname == nil { + if s.LogSendHostname != nil || t.LogSendHostname != nil { + if opt.NilSameAsEmpty { + empty := &GlobalLogSendHostname{} + if s.LogSendHostname == nil { + if !(t.LogSendHostname.Equal(*empty)) { + diff["LogSendHostname"] = []interface{}{ValueOrNil(s.LogSendHostname), ValueOrNil(t.LogSendHostname)} + } + } + if t.LogSendHostname == nil { + if !(s.LogSendHostname.Equal(*empty)) { + diff["LogSendHostname"] = []interface{}{ValueOrNil(s.LogSendHostname), ValueOrNil(t.LogSendHostname)} + } + } + } else { + diff["LogSendHostname"] = []interface{}{ValueOrNil(s.LogSendHostname), ValueOrNil(t.LogSendHostname)} + } + } + } else if !s.LogSendHostname.Equal(*t.LogSendHostname, opt) { diff["LogSendHostname"] = []interface{}{ValueOrNil(s.LogSendHostname), ValueOrNil(t.LogSendHostname)} } @@ -1138,7 +1318,25 @@ func (s Global) Diff(t Global, opts ...Options) map[string][]interface{} { diff["ThreadGroups"] = []interface{}{s.ThreadGroups, t.ThreadGroups} } - if !s.TuneOptions.Equal(*t.TuneOptions, opt) { + if s.TuneOptions == nil || t.TuneOptions == nil { + if s.TuneOptions != nil || t.TuneOptions != nil { + if opt.NilSameAsEmpty { + empty := &GlobalTuneOptions{} + if s.TuneOptions == nil { + if !(t.TuneOptions.Equal(*empty)) { + diff["TuneOptions"] = []interface{}{ValueOrNil(s.TuneOptions), ValueOrNil(t.TuneOptions)} + } + } + if t.TuneOptions == nil { + if !(s.TuneOptions.Equal(*empty)) { + diff["TuneOptions"] = []interface{}{ValueOrNil(s.TuneOptions), ValueOrNil(t.TuneOptions)} + } + } + } else { + diff["TuneOptions"] = []interface{}{ValueOrNil(s.TuneOptions), ValueOrNil(t.TuneOptions)} + } + } + } else if !s.TuneOptions.Equal(*t.TuneOptions, opt) { diff["TuneOptions"] = []interface{}{ValueOrNil(s.TuneOptions), ValueOrNil(t.TuneOptions)} } @@ -1162,7 +1360,25 @@ func (s Global) Diff(t Global, opts ...Options) map[string][]interface{} { diff["User"] = []interface{}{s.User, t.User} } - if !s.WurflOptions.Equal(*t.WurflOptions, opt) { + if s.WurflOptions == nil || t.WurflOptions == nil { + if s.WurflOptions != nil || t.WurflOptions != nil { + if opt.NilSameAsEmpty { + empty := &GlobalWurflOptions{} + if s.WurflOptions == nil { + if !(t.WurflOptions.Equal(*empty)) { + diff["WurflOptions"] = []interface{}{ValueOrNil(s.WurflOptions), ValueOrNil(t.WurflOptions)} + } + } + if t.WurflOptions == nil { + if !(s.WurflOptions.Equal(*empty)) { + diff["WurflOptions"] = []interface{}{ValueOrNil(s.WurflOptions), ValueOrNil(t.WurflOptions)} + } + } + } else { + diff["WurflOptions"] = []interface{}{ValueOrNil(s.WurflOptions), ValueOrNil(t.WurflOptions)} + } + } + } else if !s.WurflOptions.Equal(*t.WurflOptions, opt) { diff["WurflOptions"] = []interface{}{ValueOrNil(s.WurflOptions), ValueOrNil(t.WurflOptions)} } @@ -1574,6 +1790,7 @@ func (s RuntimeAPI) Diff(t RuntimeAPI, opts ...Options) map[string][]interface{} opt := getOptions(opts...) diff := make(map[string][]interface{}) + if !s.BindParams.Equal(t.BindParams, opt) { diff["BindParams"] = []interface{}{s.BindParams, t.BindParams} } diff --git a/models/info_compare.go b/models/info_compare.go index bd9f333d..83452044 100644 --- a/models/info_compare.go +++ b/models/info_compare.go @@ -33,11 +33,47 @@ package models func (s Info) Equal(t Info, opts ...Options) bool { opt := getOptions(opts...) - if !s.API.Equal(*t.API, opt) { + if s.API == nil || t.API == nil { + if s.API != nil || t.API != nil { + if opt.NilSameAsEmpty { + empty := &InfoAPI{} + if s.API == nil { + if !(t.API.Equal(*empty)) { + return false + } + } + if t.API == nil { + if !(s.API.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.API.Equal(*t.API, opt) { return false } - if !s.System.Equal(*t.System, opt) { + if s.System == nil || t.System == nil { + if s.System != nil || t.System != nil { + if opt.NilSameAsEmpty { + empty := &InfoSystem{} + if s.System == nil { + if !(t.System.Equal(*empty)) { + return false + } + } + if t.System == nil { + if !(s.System.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.System.Equal(*t.System, opt) { return false } @@ -61,11 +97,48 @@ func (s Info) Diff(t Info, opts ...Options) map[string][]interface{} { opt := getOptions(opts...) diff := make(map[string][]interface{}) - if !s.API.Equal(*t.API, opt) { + + if s.API == nil || t.API == nil { + if s.API != nil || t.API != nil { + if opt.NilSameAsEmpty { + empty := &InfoAPI{} + if s.API == nil { + if !(t.API.Equal(*empty)) { + diff["API"] = []interface{}{ValueOrNil(s.API), ValueOrNil(t.API)} + } + } + if t.API == nil { + if !(s.API.Equal(*empty)) { + diff["API"] = []interface{}{ValueOrNil(s.API), ValueOrNil(t.API)} + } + } + } else { + diff["API"] = []interface{}{ValueOrNil(s.API), ValueOrNil(t.API)} + } + } + } else if !s.API.Equal(*t.API, opt) { diff["API"] = []interface{}{ValueOrNil(s.API), ValueOrNil(t.API)} } - if !s.System.Equal(*t.System, opt) { + if s.System == nil || t.System == nil { + if s.System != nil || t.System != nil { + if opt.NilSameAsEmpty { + empty := &InfoSystem{} + if s.System == nil { + if !(t.System.Equal(*empty)) { + diff["System"] = []interface{}{ValueOrNil(s.System), ValueOrNil(t.System)} + } + } + if t.System == nil { + if !(s.System.Equal(*empty)) { + diff["System"] = []interface{}{ValueOrNil(s.System), ValueOrNil(t.System)} + } + } + } else { + diff["System"] = []interface{}{ValueOrNil(s.System), ValueOrNil(t.System)} + } + } + } else if !s.System.Equal(*t.System, opt) { diff["System"] = []interface{}{ValueOrNil(s.System), ValueOrNil(t.System)} } @@ -79,6 +152,7 @@ func (s Info) Diff(t Info, opts ...Options) map[string][]interface{} { // // opts ...Options are ignored in this method func (s InfoAPI) Equal(t InfoAPI, opts ...Options) bool { + if !s.BuildDate.Equal(t.BuildDate) { return false } @@ -98,6 +172,7 @@ func (s InfoAPI) Equal(t InfoAPI, opts ...Options) bool { // opts ...Options are ignored in this method func (s InfoAPI) Diff(t InfoAPI, opts ...Options) map[string][]interface{} { diff := make(map[string][]interface{}) + if !s.BuildDate.Equal(t.BuildDate) { diff["BuildDate"] = []interface{}{s.BuildDate, t.BuildDate} } @@ -125,7 +200,25 @@ func (s InfoAPI) Diff(t InfoAPI, opts ...Options) map[string][]interface{} { func (s InfoSystem) Equal(t InfoSystem, opts ...Options) bool { opt := getOptions(opts...) - if !s.CPUInfo.Equal(*t.CPUInfo, opt) { + if s.CPUInfo == nil || t.CPUInfo == nil { + if s.CPUInfo != nil || t.CPUInfo != nil { + if opt.NilSameAsEmpty { + empty := &InfoSystemCPUInfo{} + if s.CPUInfo == nil { + if !(t.CPUInfo.Equal(*empty)) { + return false + } + } + if t.CPUInfo == nil { + if !(s.CPUInfo.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.CPUInfo.Equal(*t.CPUInfo, opt) { return false } @@ -133,7 +226,25 @@ func (s InfoSystem) Equal(t InfoSystem, opts ...Options) bool { return false } - if !s.MemInfo.Equal(*t.MemInfo, opt) { + if s.MemInfo == nil || t.MemInfo == nil { + if s.MemInfo != nil || t.MemInfo != nil { + if opt.NilSameAsEmpty { + empty := &InfoSystemMemInfo{} + if s.MemInfo == nil { + if !(t.MemInfo.Equal(*empty)) { + return false + } + } + if t.MemInfo == nil { + if !(s.MemInfo.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.MemInfo.Equal(*t.MemInfo, opt) { return false } @@ -169,7 +280,26 @@ func (s InfoSystem) Diff(t InfoSystem, opts ...Options) map[string][]interface{} opt := getOptions(opts...) diff := make(map[string][]interface{}) - if !s.CPUInfo.Equal(*t.CPUInfo, opt) { + + if s.CPUInfo == nil || t.CPUInfo == nil { + if s.CPUInfo != nil || t.CPUInfo != nil { + if opt.NilSameAsEmpty { + empty := &InfoSystemCPUInfo{} + if s.CPUInfo == nil { + if !(t.CPUInfo.Equal(*empty)) { + diff["CPUInfo"] = []interface{}{ValueOrNil(s.CPUInfo), ValueOrNil(t.CPUInfo)} + } + } + if t.CPUInfo == nil { + if !(s.CPUInfo.Equal(*empty)) { + diff["CPUInfo"] = []interface{}{ValueOrNil(s.CPUInfo), ValueOrNil(t.CPUInfo)} + } + } + } else { + diff["CPUInfo"] = []interface{}{ValueOrNil(s.CPUInfo), ValueOrNil(t.CPUInfo)} + } + } + } else if !s.CPUInfo.Equal(*t.CPUInfo, opt) { diff["CPUInfo"] = []interface{}{ValueOrNil(s.CPUInfo), ValueOrNil(t.CPUInfo)} } @@ -177,7 +307,25 @@ func (s InfoSystem) Diff(t InfoSystem, opts ...Options) map[string][]interface{} diff["Hostname"] = []interface{}{s.Hostname, t.Hostname} } - if !s.MemInfo.Equal(*t.MemInfo, opt) { + if s.MemInfo == nil || t.MemInfo == nil { + if s.MemInfo != nil || t.MemInfo != nil { + if opt.NilSameAsEmpty { + empty := &InfoSystemMemInfo{} + if s.MemInfo == nil { + if !(t.MemInfo.Equal(*empty)) { + diff["MemInfo"] = []interface{}{ValueOrNil(s.MemInfo), ValueOrNil(t.MemInfo)} + } + } + if t.MemInfo == nil { + if !(s.MemInfo.Equal(*empty)) { + diff["MemInfo"] = []interface{}{ValueOrNil(s.MemInfo), ValueOrNil(t.MemInfo)} + } + } + } else { + diff["MemInfo"] = []interface{}{ValueOrNil(s.MemInfo), ValueOrNil(t.MemInfo)} + } + } + } else if !s.MemInfo.Equal(*t.MemInfo, opt) { diff["MemInfo"] = []interface{}{ValueOrNil(s.MemInfo), ValueOrNil(t.MemInfo)} } diff --git a/models/native_stat_compare.go b/models/native_stat_compare.go index 4cb70e45..ca4e27d1 100644 --- a/models/native_stat_compare.go +++ b/models/native_stat_compare.go @@ -41,7 +41,25 @@ func (s NativeStat) Equal(t NativeStat, opts ...Options) bool { return false } - if !s.Stats.Equal(*t.Stats, opt) { + if s.Stats == nil || t.Stats == nil { + if s.Stats != nil || t.Stats != nil { + if opt.NilSameAsEmpty { + empty := &NativeStatStats{} + if s.Stats == nil { + if !(t.Stats.Equal(*empty)) { + return false + } + } + if t.Stats == nil { + if !(s.Stats.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Stats.Equal(*t.Stats, opt) { return false } @@ -77,7 +95,25 @@ func (s NativeStat) Diff(t NativeStat, opts ...Options) map[string][]interface{} diff["Name"] = []interface{}{s.Name, t.Name} } - if !s.Stats.Equal(*t.Stats, opt) { + if s.Stats == nil || t.Stats == nil { + if s.Stats != nil || t.Stats != nil { + if opt.NilSameAsEmpty { + empty := &NativeStatStats{} + if s.Stats == nil { + if !(t.Stats.Equal(*empty)) { + diff["Stats"] = []interface{}{ValueOrNil(s.Stats), ValueOrNil(t.Stats)} + } + } + if t.Stats == nil { + if !(s.Stats.Equal(*empty)) { + diff["Stats"] = []interface{}{ValueOrNil(s.Stats), ValueOrNil(t.Stats)} + } + } + } else { + diff["Stats"] = []interface{}{ValueOrNil(s.Stats), ValueOrNil(t.Stats)} + } + } + } else if !s.Stats.Equal(*t.Stats, opt) { diff["Stats"] = []interface{}{ValueOrNil(s.Stats), ValueOrNil(t.Stats)} } diff --git a/models/peer_section_compare.go b/models/peer_section_compare.go index 1ea5bd72..43841c07 100644 --- a/models/peer_section_compare.go +++ b/models/peer_section_compare.go @@ -33,11 +33,47 @@ package models func (s PeerSection) Equal(t PeerSection, opts ...Options) bool { opt := getOptions(opts...) - if !s.DefaultBind.Equal(*t.DefaultBind, opt) { + if s.DefaultBind == nil || t.DefaultBind == nil { + if s.DefaultBind != nil || t.DefaultBind != nil { + if opt.NilSameAsEmpty { + empty := &DefaultBind{} + if s.DefaultBind == nil { + if !(t.DefaultBind.Equal(*empty)) { + return false + } + } + if t.DefaultBind == nil { + if !(s.DefaultBind.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.DefaultBind.Equal(*t.DefaultBind, opt) { return false } - if !s.DefaultServer.Equal(*t.DefaultServer, opt) { + if s.DefaultServer == nil || t.DefaultServer == nil { + if s.DefaultServer != nil || t.DefaultServer != nil { + if opt.NilSameAsEmpty { + empty := &DefaultServer{} + if s.DefaultServer == nil { + if !(t.DefaultServer.Equal(*empty)) { + return false + } + } + if t.DefaultServer == nil { + if !(s.DefaultServer.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.DefaultServer.Equal(*t.DefaultServer, opt) { return false } @@ -77,11 +113,48 @@ func (s PeerSection) Diff(t PeerSection, opts ...Options) map[string][]interface opt := getOptions(opts...) diff := make(map[string][]interface{}) - if !s.DefaultBind.Equal(*t.DefaultBind, opt) { + + if s.DefaultBind == nil || t.DefaultBind == nil { + if s.DefaultBind != nil || t.DefaultBind != nil { + if opt.NilSameAsEmpty { + empty := &DefaultBind{} + if s.DefaultBind == nil { + if !(t.DefaultBind.Equal(*empty)) { + diff["DefaultBind"] = []interface{}{ValueOrNil(s.DefaultBind), ValueOrNil(t.DefaultBind)} + } + } + if t.DefaultBind == nil { + if !(s.DefaultBind.Equal(*empty)) { + diff["DefaultBind"] = []interface{}{ValueOrNil(s.DefaultBind), ValueOrNil(t.DefaultBind)} + } + } + } else { + diff["DefaultBind"] = []interface{}{ValueOrNil(s.DefaultBind), ValueOrNil(t.DefaultBind)} + } + } + } else if !s.DefaultBind.Equal(*t.DefaultBind, opt) { diff["DefaultBind"] = []interface{}{ValueOrNil(s.DefaultBind), ValueOrNil(t.DefaultBind)} } - if !s.DefaultServer.Equal(*t.DefaultServer, opt) { + if s.DefaultServer == nil || t.DefaultServer == nil { + if s.DefaultServer != nil || t.DefaultServer != nil { + if opt.NilSameAsEmpty { + empty := &DefaultServer{} + if s.DefaultServer == nil { + if !(t.DefaultServer.Equal(*empty)) { + diff["DefaultServer"] = []interface{}{ValueOrNil(s.DefaultServer), ValueOrNil(t.DefaultServer)} + } + } + if t.DefaultServer == nil { + if !(s.DefaultServer.Equal(*empty)) { + diff["DefaultServer"] = []interface{}{ValueOrNil(s.DefaultServer), ValueOrNil(t.DefaultServer)} + } + } + } else { + diff["DefaultServer"] = []interface{}{ValueOrNil(s.DefaultServer), ValueOrNil(t.DefaultServer)} + } + } + } else if !s.DefaultServer.Equal(*t.DefaultServer, opt) { diff["DefaultServer"] = []interface{}{ValueOrNil(s.DefaultServer), ValueOrNil(t.DefaultServer)} } diff --git a/models/process_info_compare.go b/models/process_info_compare.go index 3b8958d7..dcb97026 100644 --- a/models/process_info_compare.go +++ b/models/process_info_compare.go @@ -37,7 +37,25 @@ func (s ProcessInfo) Equal(t ProcessInfo, opts ...Options) bool { return false } - if !s.Info.Equal(*t.Info, opt) { + if s.Info == nil || t.Info == nil { + if s.Info != nil || t.Info != nil { + if opt.NilSameAsEmpty { + empty := &ProcessInfoItem{} + if s.Info == nil { + if !(t.Info.Equal(*empty)) { + return false + } + } + if t.Info == nil { + if !(s.Info.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Info.Equal(*t.Info, opt) { return false } @@ -69,7 +87,25 @@ func (s ProcessInfo) Diff(t ProcessInfo, opts ...Options) map[string][]interface diff["Error"] = []interface{}{s.Error, t.Error} } - if !s.Info.Equal(*t.Info, opt) { + if s.Info == nil || t.Info == nil { + if s.Info != nil || t.Info != nil { + if opt.NilSameAsEmpty { + empty := &ProcessInfoItem{} + if s.Info == nil { + if !(t.Info.Equal(*empty)) { + diff["Info"] = []interface{}{ValueOrNil(s.Info), ValueOrNil(t.Info)} + } + } + if t.Info == nil { + if !(s.Info.Equal(*empty)) { + diff["Info"] = []interface{}{ValueOrNil(s.Info), ValueOrNil(t.Info)} + } + } + } else { + diff["Info"] = []interface{}{ValueOrNil(s.Info), ValueOrNil(t.Info)} + } + } + } else if !s.Info.Equal(*t.Info, opt) { diff["Info"] = []interface{}{ValueOrNil(s.Info), ValueOrNil(t.Info)} } diff --git a/models/server_compare.go b/models/server_compare.go index 112bb76b..54efdace 100644 --- a/models/server_compare.go +++ b/models/server_compare.go @@ -73,6 +73,7 @@ func (s Server) Diff(t Server, opts ...Options) map[string][]interface{} { opt := getOptions(opts...) diff := make(map[string][]interface{}) + if !s.ServerParams.Equal(t.ServerParams, opt) { diff["ServerParams"] = []interface{}{s.ServerParams, t.ServerParams} } diff --git a/models/server_template_compare.go b/models/server_template_compare.go index 2992ce65..70c9b9b3 100644 --- a/models/server_template_compare.go +++ b/models/server_template_compare.go @@ -77,6 +77,7 @@ func (s ServerTemplate) Diff(t ServerTemplate, opts ...Options) map[string][]int opt := getOptions(opts...) diff := make(map[string][]interface{}) + if !s.ServerParams.Equal(t.ServerParams, opt) { diff["ServerParams"] = []interface{}{s.ServerParams, t.ServerParams} } diff --git a/models/site_compare.go b/models/site_compare.go index 8a27d38b..f7d86ba2 100644 --- a/models/site_compare.go +++ b/models/site_compare.go @@ -51,7 +51,25 @@ func (s Site) Equal(t Site, opts ...Options) bool { return false } - if !s.Service.Equal(*t.Service, opt) { + if s.Service == nil || t.Service == nil { + if s.Service != nil || t.Service != nil { + if opt.NilSameAsEmpty { + empty := &SiteService{} + if s.Service == nil { + if !(t.Service.Equal(*empty)) { + return false + } + } + if t.Service == nil { + if !(s.Service.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Service.Equal(*t.Service, opt) { return false } @@ -96,7 +114,25 @@ func (s Site) Diff(t Site, opts ...Options) map[string][]interface{} { diff["Name"] = []interface{}{s.Name, t.Name} } - if !s.Service.Equal(*t.Service, opt) { + if s.Service == nil || t.Service == nil { + if s.Service != nil || t.Service != nil { + if opt.NilSameAsEmpty { + empty := &SiteService{} + if s.Service == nil { + if !(t.Service.Equal(*empty)) { + diff["Service"] = []interface{}{ValueOrNil(s.Service), ValueOrNil(t.Service)} + } + } + if t.Service == nil { + if !(s.Service.Equal(*empty)) { + diff["Service"] = []interface{}{ValueOrNil(s.Service), ValueOrNil(t.Service)} + } + } + } else { + diff["Service"] = []interface{}{ValueOrNil(s.Service), ValueOrNil(t.Service)} + } + } + } else if !s.Service.Equal(*t.Service, opt) { diff["Service"] = []interface{}{ValueOrNil(s.Service), ValueOrNil(t.Service)} } @@ -119,7 +155,25 @@ func (s Site) Diff(t Site, opts ...Options) map[string][]interface{} { func (s SiteFarm) Equal(t SiteFarm, opts ...Options) bool { opt := getOptions(opts...) - if !s.Balance.Equal(*t.Balance, opt) { + if s.Balance == nil || t.Balance == nil { + if s.Balance != nil || t.Balance != nil { + if opt.NilSameAsEmpty { + empty := &Balance{} + if s.Balance == nil { + if !(t.Balance.Equal(*empty)) { + return false + } + } + if t.Balance == nil { + if !(s.Balance.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Balance.Equal(*t.Balance, opt) { return false } @@ -131,7 +185,25 @@ func (s SiteFarm) Equal(t SiteFarm, opts ...Options) bool { return false } - if !s.Forwardfor.Equal(*t.Forwardfor, opt) { + if s.Forwardfor == nil || t.Forwardfor == nil { + if s.Forwardfor != nil || t.Forwardfor != nil { + if opt.NilSameAsEmpty { + empty := &Forwardfor{} + if s.Forwardfor == nil { + if !(t.Forwardfor.Equal(*empty)) { + return false + } + } + if t.Forwardfor == nil { + if !(s.Forwardfor.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Forwardfor.Equal(*t.Forwardfor, opt) { return false } @@ -177,7 +249,26 @@ func (s SiteFarm) Diff(t SiteFarm, opts ...Options) map[string][]interface{} { opt := getOptions(opts...) diff := make(map[string][]interface{}) - if !s.Balance.Equal(*t.Balance, opt) { + + if s.Balance == nil || t.Balance == nil { + if s.Balance != nil || t.Balance != nil { + if opt.NilSameAsEmpty { + empty := &Balance{} + if s.Balance == nil { + if !(t.Balance.Equal(*empty)) { + diff["Balance"] = []interface{}{ValueOrNil(s.Balance), ValueOrNil(t.Balance)} + } + } + if t.Balance == nil { + if !(s.Balance.Equal(*empty)) { + diff["Balance"] = []interface{}{ValueOrNil(s.Balance), ValueOrNil(t.Balance)} + } + } + } else { + diff["Balance"] = []interface{}{ValueOrNil(s.Balance), ValueOrNil(t.Balance)} + } + } + } else if !s.Balance.Equal(*t.Balance, opt) { diff["Balance"] = []interface{}{ValueOrNil(s.Balance), ValueOrNil(t.Balance)} } @@ -189,7 +280,25 @@ func (s SiteFarm) Diff(t SiteFarm, opts ...Options) map[string][]interface{} { diff["CondTest"] = []interface{}{s.CondTest, t.CondTest} } - if !s.Forwardfor.Equal(*t.Forwardfor, opt) { + if s.Forwardfor == nil || t.Forwardfor == nil { + if s.Forwardfor != nil || t.Forwardfor != nil { + if opt.NilSameAsEmpty { + empty := &Forwardfor{} + if s.Forwardfor == nil { + if !(t.Forwardfor.Equal(*empty)) { + diff["Forwardfor"] = []interface{}{ValueOrNil(s.Forwardfor), ValueOrNil(t.Forwardfor)} + } + } + if t.Forwardfor == nil { + if !(s.Forwardfor.Equal(*empty)) { + diff["Forwardfor"] = []interface{}{ValueOrNil(s.Forwardfor), ValueOrNil(t.Forwardfor)} + } + } + } else { + diff["Forwardfor"] = []interface{}{ValueOrNil(s.Forwardfor), ValueOrNil(t.Forwardfor)} + } + } + } else if !s.Forwardfor.Equal(*t.Forwardfor, opt) { diff["Forwardfor"] = []interface{}{ValueOrNil(s.Forwardfor), ValueOrNil(t.Forwardfor)} } diff --git a/models/spoe_message_compare.go b/models/spoe_message_compare.go index ae660cbc..6684a31e 100644 --- a/models/spoe_message_compare.go +++ b/models/spoe_message_compare.go @@ -41,7 +41,25 @@ func (s SpoeMessage) Equal(t SpoeMessage, opts ...Options) bool { return false } - if !s.Event.Equal(*t.Event, opt) { + if s.Event == nil || t.Event == nil { + if s.Event != nil || t.Event != nil { + if opt.NilSameAsEmpty { + empty := &SpoeMessageEvent{} + if s.Event == nil { + if !(t.Event.Equal(*empty)) { + return false + } + } + if t.Event == nil { + if !(s.Event.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.Event.Equal(*t.Event, opt) { return false } @@ -69,6 +87,7 @@ func (s SpoeMessage) Diff(t SpoeMessage, opts ...Options) map[string][]interface opt := getOptions(opts...) diff := make(map[string][]interface{}) + if !s.ACL.Equal(t.ACL, opt) { diff["ACL"] = []interface{}{s.ACL, t.ACL} } @@ -77,7 +96,25 @@ func (s SpoeMessage) Diff(t SpoeMessage, opts ...Options) map[string][]interface diff["Args"] = []interface{}{s.Args, t.Args} } - if !s.Event.Equal(*t.Event, opt) { + if s.Event == nil || t.Event == nil { + if s.Event != nil || t.Event != nil { + if opt.NilSameAsEmpty { + empty := &SpoeMessageEvent{} + if s.Event == nil { + if !(t.Event.Equal(*empty)) { + diff["Event"] = []interface{}{ValueOrNil(s.Event), ValueOrNil(t.Event)} + } + } + if t.Event == nil { + if !(s.Event.Equal(*empty)) { + diff["Event"] = []interface{}{ValueOrNil(s.Event), ValueOrNil(t.Event)} + } + } + } else { + diff["Event"] = []interface{}{ValueOrNil(s.Event), ValueOrNil(t.Event)} + } + } + } else if !s.Event.Equal(*t.Event, opt) { diff["Event"] = []interface{}{ValueOrNil(s.Event), ValueOrNil(t.Event)} } diff --git a/models/ssl_certificate_compare.go b/models/ssl_certificate_compare.go index 496ab058..d8804018 100644 --- a/models/ssl_certificate_compare.go +++ b/models/ssl_certificate_compare.go @@ -17,13 +17,26 @@ package models +import ( + "github.com/go-openapi/strfmt" +) + // Equal checks if two structs of type SslCertificate are equal // +// By default empty maps and slices are equal to nil: +// // var a, b SslCertificate // equal := a.Equal(b) // -// opts ...Options are ignored in this method +// For more advanced use case you can configure these options (default values are shown): +// +// var a, b SslCertificate +// equal := a.Equal(b,Options{ +// NilSameAsEmpty: true, +// }) func (s SslCertificate) Equal(t SslCertificate, opts ...Options) bool { + opt := getOptions(opts...) + if s.Description != t.Description { return false } @@ -44,11 +57,47 @@ func (s SslCertificate) Equal(t SslCertificate, opts ...Options) bool { return false } - if !s.NotAfter.Equal(*t.NotAfter) { + if s.NotAfter == nil || t.NotAfter == nil { + if s.NotAfter != nil || t.NotAfter != nil { + if opt.NilSameAsEmpty { + empty := &strfmt.DateTime{} + if s.NotAfter == nil { + if !(t.NotAfter.Equal(*empty)) { + return false + } + } + if t.NotAfter == nil { + if !(s.NotAfter.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.NotAfter.Equal(*t.NotAfter) { return false } - if !s.NotBefore.Equal(*t.NotBefore) { + if s.NotBefore == nil || t.NotBefore == nil { + if s.NotBefore != nil || t.NotBefore != nil { + if opt.NilSameAsEmpty { + empty := &strfmt.DateTime{} + if s.NotBefore == nil { + if !(t.NotBefore.Equal(*empty)) { + return false + } + } + if t.NotBefore == nil { + if !(s.NotBefore.Equal(*empty)) { + return false + } + } + } else { + return false + } + } + } else if !s.NotBefore.Equal(*t.NotBefore) { return false } @@ -65,11 +114,20 @@ func (s SslCertificate) Equal(t SslCertificate, opts ...Options) bool { // Diff checks if two structs of type SslCertificate are equal // +// By default empty maps and slices are equal to nil: +// // var a, b SslCertificate // diff := a.Diff(b) // -// opts ...Options are ignored in this method +// For more advanced use case you can configure these options (default values are shown): +// +// var a, b SslCertificate +// diff := a.Diff(b,Options{ +// NilSameAsEmpty: true, +// }) func (s SslCertificate) Diff(t SslCertificate, opts ...Options) map[string][]interface{} { + opt := getOptions(opts...) + diff := make(map[string][]interface{}) if s.Description != t.Description { diff["Description"] = []interface{}{s.Description, t.Description} @@ -91,11 +149,47 @@ func (s SslCertificate) Diff(t SslCertificate, opts ...Options) map[string][]int diff["Issuers"] = []interface{}{s.Issuers, t.Issuers} } - if !s.NotAfter.Equal(*t.NotAfter) { + if s.NotAfter == nil || t.NotAfter == nil { + if s.NotAfter != nil || t.NotAfter != nil { + if opt.NilSameAsEmpty { + empty := &strfmt.DateTime{} + if s.NotAfter == nil { + if !(t.NotAfter.Equal(*empty)) { + diff["NotAfter"] = []interface{}{ValueOrNil(s.NotAfter), ValueOrNil(t.NotAfter)} + } + } + if t.NotAfter == nil { + if !(s.NotAfter.Equal(*empty)) { + diff["NotAfter"] = []interface{}{ValueOrNil(s.NotAfter), ValueOrNil(t.NotAfter)} + } + } + } else { + diff["NotAfter"] = []interface{}{ValueOrNil(s.NotAfter), ValueOrNil(t.NotAfter)} + } + } + } else if !s.NotAfter.Equal(*t.NotAfter) { diff["NotAfter"] = []interface{}{ValueOrNil(s.NotAfter), ValueOrNil(t.NotAfter)} } - if !s.NotBefore.Equal(*t.NotBefore) { + if s.NotBefore == nil || t.NotBefore == nil { + if s.NotBefore != nil || t.NotBefore != nil { + if opt.NilSameAsEmpty { + empty := &strfmt.DateTime{} + if s.NotBefore == nil { + if !(t.NotBefore.Equal(*empty)) { + diff["NotBefore"] = []interface{}{ValueOrNil(s.NotBefore), ValueOrNil(t.NotBefore)} + } + } + if t.NotBefore == nil { + if !(s.NotBefore.Equal(*empty)) { + diff["NotBefore"] = []interface{}{ValueOrNil(s.NotBefore), ValueOrNil(t.NotBefore)} + } + } + } else { + diff["NotBefore"] = []interface{}{ValueOrNil(s.NotBefore), ValueOrNil(t.NotBefore)} + } + } + } else if !s.NotBefore.Equal(*t.NotBefore) { diff["NotBefore"] = []interface{}{ValueOrNil(s.NotBefore), ValueOrNil(t.NotBefore)} }