-
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.
feat: improve messages in response (#26)
- Loading branch information
Showing
14 changed files
with
155 additions
and
161 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,23 @@ | ||
package messages | ||
|
||
import "errors" | ||
|
||
type Message struct { | ||
Id interface{} | ||
Body []byte | ||
acked bool | ||
acked *bool | ||
} | ||
|
||
func (m Message) Nack() (Message, error) { | ||
err := m.setAsAcked() | ||
if err != nil { | ||
return Message{}, err | ||
} | ||
|
||
return Message{ | ||
Id: m.Id, | ||
Body: []byte{0}, | ||
}, nil | ||
func (m *Message) IsAcked() bool { | ||
return m.acked != nil && *m.acked | ||
} | ||
|
||
func (m Message) Ack() (Message, error) { | ||
err := m.setAsAcked() | ||
if err != nil { | ||
return Message{}, err | ||
} | ||
|
||
return Message{ | ||
Id: m.Id, | ||
Body: []byte{1}, | ||
}, nil | ||
func (m *Message) IsNacked() bool { | ||
return m.acked != nil && !*m.acked | ||
} | ||
|
||
func (m *Message) setAsAcked() error { | ||
if m.acked { | ||
return errors.New("Message already acked") | ||
} | ||
|
||
m.acked = true | ||
func (m *Message) Nack() { | ||
m.acked = func(b bool) *bool { return &b }(false) | ||
} | ||
|
||
return nil | ||
func (m *Message) Ack() { | ||
m.acked = func(b bool) *bool { return &b }(true) | ||
} |
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
Oops, something went wrong.