You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by fu...@apache.org on 2023/03/31 02:51:14 UTC

[rocketmq-clients] branch master updated: add 'AddProperty' (#432)

This is an automated email from the ASF dual-hosted git repository.

fuyou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git


The following commit(s) were added to refs/heads/master by this push:
     new 90eecba0 add 'AddProperty' (#432)
90eecba0 is described below

commit 90eecba0d2797bc3cd90b29aafb6a2f719475174
Author: guyinyou <36...@users.noreply.github.com>
AuthorDate: Fri Mar 31 10:51:09 2023 +0800

    add 'AddProperty' (#432)
    
    Co-authored-by: guyinyou <gu...@alibaba-inc.com>
---
 golang/message.go | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/golang/message.go b/golang/message.go
index 00586b18..9d1007f1 100644
--- a/golang/message.go
+++ b/golang/message.go
@@ -103,10 +103,21 @@ func (msg *Message) SetKeys(keys ...string) {
 	msg.keys = keys
 }
 
-func (msg *Message) GetProperties() map[string]string {
+func (msg *Message) getOrNewProperties() map[string]string {
+	if msg.properties == nil {
+		msg.properties = make(map[string]string)
+	}
 	return msg.properties
 }
 
+func (msg *Message) GetProperties() map[string]string {
+	return msg.getOrNewProperties()
+}
+
+func (msg *Message) AddProperty(key, value string) {
+	msg.getOrNewProperties()[key] = value
+}
+
 func (msg *Message) SetDelayTimestamp(deliveryTimestamp time.Time) {
 	msg.deliveryTimestamp = &deliveryTimestamp
 }