From 50e2103ccd197dbd8b030d79df49f9f5a82f3b7f Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Thu, 28 Jan 2021 23:43:05 -0500 Subject: [PATCH 1/2] Go modules and fix nil map in extensions --- go.mod | 8 ++++++++ go.sum | 15 +++++++++++++++ response.go | 7 ++++++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f5e58d1 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module github.com/karmanyaahm/wray + +go 1.15 + +require ( + github.com/autogrowsystems/wray v0.0.0-20160519030252-f36984f6648c + github.com/smartystreets/goconvey v1.6.4 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d6c7964 --- /dev/null +++ b/go.sum @@ -0,0 +1,15 @@ +github.com/autogrowsystems/wray v0.0.0-20160519030252-f36984f6648c h1:Ncrbw3+cxaFNTp/I3pbV8MZKUG7DbNYatYTJlDJn4gw= +github.com/autogrowsystems/wray v0.0.0-20160519030252-f36984f6648c/go.mod h1:druJ8QMeBCUmwJ7ZSFowx77dWxEWF3SYlQlsqZaLZQg= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= diff --git a/response.go b/response.go index ee133a5..81a4fc3 100644 --- a/response.go +++ b/response.go @@ -66,7 +66,12 @@ func (w msgWrapper) Channel() string { return w.msg.Channel } // Ext returns a map of extension data. As it is a map (and thus a pointer), changes // to the returned object will modify the content of this field in the message -func (w msgWrapper) Ext() map[string]interface{} { return w.msg.Ext } +func (w msgWrapper) Ext() map[string]interface{} { + if len(w.msg.Ext) == 0 { + w.msg.Ext = map[string]interface{}{} + } + return w.msg.Ext +} func (w msgWrapper) OK() bool { return w.msg.Successful } func (w msgWrapper) Error() string { return w.msg.Error } func (w msgWrapper) HasError() bool { return w.msg.Error != "" } From 756d58657c146a25dd7351cde88354b955043e63 Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Wed, 3 Mar 2021 18:34:35 -0500 Subject: [PATCH 2/2] Check map nil not length --- response.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/response.go b/response.go index 81a4fc3..dbc2866 100644 --- a/response.go +++ b/response.go @@ -67,7 +67,7 @@ func (w msgWrapper) Channel() string { return w.msg.Channel } // Ext returns a map of extension data. As it is a map (and thus a pointer), changes // to the returned object will modify the content of this field in the message func (w msgWrapper) Ext() map[string]interface{} { - if len(w.msg.Ext) == 0 { + if w.msg.Ext == nil { w.msg.Ext = map[string]interface{}{} } return w.msg.Ext