From bb18292b159c761e2fbf56ac480ec8e0e398818d Mon Sep 17 00:00:00 2001 From: Allen Li Date: Fri, 9 May 2025 17:27:33 +0800 Subject: [PATCH] fix: support source namespace --- README.md | 1 + v3/eventstream.go | 8 ++++++++ v3/kafka.go | 1 + v3/stdout.go | 1 + 4 files changed, 11 insertions(+) diff --git a/README.md b/README.md index edddd64..c7b1f39 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,7 @@ err := client.Publish( * ClientIDs : List of client IDs. Backward compatibility. ([]string - UUID v4 without Hyphens) * TargetUserIDs : List of target client IDs. Backward compatibility. ([]string - UUID v4 without Hyphens) * TargetNamespace : Target Namespace. Backward compatibility. (string) +* SourceNamespace : Source Namespace. Backward compatibility. SourceNamespace tracks the trigger namespace, distinct from the event's occurrence namespace. (string - optional) * Privacy : Privacy. Backward compatibility. (bool) * AdditionalFields : Additional fields. Backward compatibility. (map[string]interface{}) * Payload : Additional attribute. (map[string]interface{}) diff --git a/v3/eventstream.go b/v3/eventstream.go index 7a76c33..afc4e2e 100644 --- a/v3/eventstream.go +++ b/v3/eventstream.go @@ -77,6 +77,7 @@ type Event struct { TargetNamespace string `json:"target_namespace,omitempty"` Privacy bool `json:"privacy,omitempty"` Topic string `json:"topic,omitempty"` + SourceNamespace string `json:"sourceNamespace,omitempty"` AdditionalFields map[string]interface{} `json:"additional_fields,omitempty"` Payload map[string]interface{} `json:"payload,omitempty"` @@ -141,6 +142,7 @@ type PublishBuilder struct { errorCallback func(event *Event, err error) ctx context.Context timeout time.Duration + sourceNamespace string } // NewPublish create new PublishBuilder instance @@ -259,6 +261,12 @@ func (p *PublishBuilder) TargetNamespace(targetNamespace string) *PublishBuilder return p } +// SourceNamespace set sourceNamespace of publisher event +func (p *PublishBuilder) SourceNamespace(sourceNamespace string) *PublishBuilder { + p.sourceNamespace = sourceNamespace + return p +} + // Privacy set privacy of publisher event func (p *PublishBuilder) Privacy(privacy bool) *PublishBuilder { p.privacy = privacy diff --git a/v3/kafka.go b/v3/kafka.go index 1a52745..edaffe6 100644 --- a/v3/kafka.go +++ b/v3/kafka.go @@ -538,6 +538,7 @@ func ConstructEvent(publishBuilder *PublishBuilder) (kafka.Message, *Event, erro Privacy: publishBuilder.privacy, AdditionalFields: publishBuilder.additionalFields, Payload: publishBuilder.payload, + SourceNamespace: publishBuilder.sourceNamespace, } eventBytes, err := marshal(event) diff --git a/v3/stdout.go b/v3/stdout.go index c6b601e..b375e51 100644 --- a/v3/stdout.go +++ b/v3/stdout.go @@ -71,6 +71,7 @@ func (client *StdoutClient) Publish(publishBuilder *PublishBuilder) error { AdditionalFields: publishBuilder.additionalFields, Version: publishBuilder.version, Payload: publishBuilder.payload, + SourceNamespace: publishBuilder.sourceNamespace, } eventByte, err := marshal(event)