-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
95 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,43 @@ | ||
package goeventbus | ||
|
||
type Message struct { | ||
Data interface{} | ||
MessageOptions MessageOptions | ||
Payload interface{} | ||
Headers MessageHeaders | ||
} | ||
|
||
// Returns an empty message | ||
func CreateMessage() Message { | ||
return Message{} | ||
type MessageBuilder interface { | ||
SetPayload(payload any) MessageBuilder | ||
SetHeaders(headers MessageHeaders) MessageBuilder | ||
Build() Message | ||
} | ||
|
||
// Set the body of the message. Paramater can be any type | ||
func (m Message) SetBody(data any) Message { | ||
m.Data = data | ||
return m | ||
type defaultMessageBuilder struct { | ||
message Message | ||
} | ||
|
||
// Set the options of the message. For create a new options see: NewMessageOptions() | ||
func (m Message) SetOptions(options MessageOptions) Message { | ||
m.MessageOptions = options | ||
return m | ||
func NewMessageBuilder() MessageBuilder { | ||
return &defaultMessageBuilder{message: Message{}} | ||
} | ||
|
||
func (mb *defaultMessageBuilder) SetPayload(payload any) MessageBuilder { | ||
mb.message.Payload = payload | ||
return mb | ||
} | ||
|
||
func (mb *defaultMessageBuilder) SetHeaders(headers MessageHeaders) MessageBuilder { | ||
mb.message.Headers = headers | ||
return mb | ||
} | ||
|
||
func (mb *defaultMessageBuilder) Build() Message { | ||
return mb.message | ||
} | ||
|
||
// Returns data of the message | ||
func (m Message) Extract() any { | ||
return m.Data | ||
return m.Payload | ||
} | ||
|
||
// Returns options of the message | ||
func (m Message) Options() MessageOptions { | ||
return m.MessageOptions | ||
func (m Message) ExtractHeaders() MessageHeaders { | ||
return m.Headers | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package goeventbus | ||
|
||
type Headers struct { | ||
headers map[string]string | ||
} | ||
|
||
type MessageHeaders struct { | ||
headers Headers | ||
} | ||
|
||
type MessageHeadersBuilder interface { | ||
SetHeader(key string, value string) MessageHeadersBuilder | ||
Build() MessageHeaders | ||
} | ||
|
||
type defaultMessageHeadersBuilder struct { | ||
messageHeaders MessageHeaders | ||
} | ||
|
||
func NewMessageHeadersBuilder() MessageHeadersBuilder { | ||
return &defaultMessageHeadersBuilder{messageHeaders: MessageHeaders{Headers{headers: map[string]string{}}}} | ||
} | ||
|
||
func (hb *defaultMessageHeadersBuilder) SetHeader(key string, value string) MessageHeadersBuilder { | ||
hb.messageHeaders.headers.headers[key] = value | ||
return hb | ||
} | ||
|
||
func (hb *defaultMessageHeadersBuilder) Build() MessageHeaders { | ||
return hb.messageHeaders | ||
} | ||
|
||
func NewMessageHeaders() MessageHeaders { | ||
return MessageHeaders{ | ||
headers: Headers{}, | ||
} | ||
} | ||
|
||
func (h MessageHeaders) Get(key string) string { | ||
return h.headers.headers[key] | ||
} | ||
|
||
func (h MessageHeaders) Contains(key string) bool { | ||
_, exist := h.headers.headers[key] | ||
return exist | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters