-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Implemented multiple reports per message (#15)
Closes #11
- Loading branch information
Showing
5 changed files
with
57 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,52 @@ | ||
package rbforwarder | ||
|
||
import "errors" | ||
import ( | ||
"errors" | ||
|
||
"github.com/oleiade/lane" | ||
) | ||
|
||
// message is used to send data through the pipeline | ||
type message struct { | ||
bufferStack [][]byte | ||
|
||
payload *lane.Stack | ||
opts *lane.Stack | ||
seq uint64 // Unique ID for the report, used to maintain sequence | ||
status string // Result of the sending | ||
code int // Result of the sending | ||
retries int | ||
opts map[string]interface{} | ||
channel chan *message | ||
} | ||
|
||
// PushData store data on an LIFO queue so the nexts handlers can use it | ||
func (m *message) PushData(v []byte) { | ||
m.bufferStack = append(m.bufferStack, v) | ||
if m.payload == nil { | ||
m.payload = lane.NewStack() | ||
} | ||
|
||
m.payload.Push(v) | ||
} | ||
|
||
// PopData get the data stored by the previous handler | ||
func (m *message) PopData() (ret []byte, err error) { | ||
if len(m.bufferStack) < 1 { | ||
err = errors.New("No data on the stack") | ||
if m.payload.Empty() { | ||
err = errors.New("Empty stack") | ||
return | ||
} | ||
|
||
ret = m.bufferStack[len(m.bufferStack)-1] | ||
m.bufferStack = m.bufferStack[0 : len(m.bufferStack)-1] | ||
ret = m.payload.Pop().([]byte) | ||
|
||
return | ||
} | ||
|
||
// GetOpt returns an option | ||
func (m message) GetOpt(name string) interface{} { | ||
return m.opts[name] | ||
} | ||
func (m message) GetReports() []Report { | ||
var reports []Report | ||
|
||
func (m message) GetReport() Report { | ||
return Report{ | ||
code: m.code, | ||
status: m.status, | ||
retries: m.retries, | ||
opts: m.opts, | ||
for !m.opts.Empty() { | ||
reports = append(reports, Report{ | ||
code: m.code, | ||
status: m.status, | ||
retries: m.retries, | ||
opts: m.opts.Pop().(map[string]interface{}), | ||
}) | ||
} | ||
|
||
return reports | ||
} |
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