use metadata.Metadata (#8)

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2020-11-18 16:50:41 +03:00
committed by GitHub
parent e0ef8b2953
commit daffa9e548
28 changed files with 119 additions and 84 deletions

View File

@@ -6,6 +6,8 @@ import (
"encoding/json"
"errors"
"time"
"github.com/unistack-org/micro/v3/metadata"
)
var (
@@ -36,7 +38,7 @@ type Event struct {
// Timestamp of the event
Timestamp time.Time
// Metadata contains the encoded event was indexed by
Metadata map[string]string
Metadata metadata.Metadata
// Payload contains the encoded message
Payload []byte
}

View File

@@ -1,11 +1,15 @@
package events
import "time"
import (
"time"
"github.com/unistack-org/micro/v3/metadata"
)
// PublishOptions contains all the options which can be provided when publishing an event
type PublishOptions struct {
// Metadata contains any keys which can be used to query the data, for example a customer id
Metadata map[string]string
Metadata metadata.Metadata
// Timestamp to set for the event, if the timestamp is a zero value, the current time will be used
Timestamp time.Time
}
@@ -14,9 +18,9 @@ type PublishOptions struct {
type PublishOption func(o *PublishOptions)
// WithMetadata sets the Metadata field on PublishOptions
func WithMetadata(md map[string]string) PublishOption {
func WithMetadata(md metadata.Metadata) PublishOption {
return func(o *PublishOptions) {
o.Metadata = md
o.Metadata = metadata.Copy(md)
}
}