-
-
Notifications
You must be signed in to change notification settings - Fork 704
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Subscribe endpoint consolidation; same behavior for all endpoints; ke…
…epalive
- Loading branch information
Philipp Heckel
committed
Oct 27, 2021
1 parent
b72afb1
commit a38aca4
Showing
8 changed files
with
153 additions
and
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package server | ||
|
||
import "time" | ||
|
||
// List of possible events | ||
const ( | ||
openEvent = "open" | ||
keepaliveEvent = "keepalive" | ||
) | ||
|
||
// message represents a message published to a topic | ||
type message struct { | ||
Time int64 `json:"time"` // Unix time in seconds | ||
Event string `json:"event,omitempty"` // One of the above | ||
Message string `json:"message,omitempty"` | ||
} | ||
|
||
// messageEncoder is a function that knows how to encode a message | ||
type messageEncoder func(msg *message) (string, error) | ||
|
||
// newMessage creates a new message with the current timestamp | ||
func newMessage(event string, msg string) *message { | ||
return &message{ | ||
Time: time.Now().Unix(), | ||
Event: event, | ||
Message: msg, | ||
} | ||
} | ||
|
||
// newOpenMessage is a convenience method to create an open message | ||
func newOpenMessage() *message { | ||
return newMessage(openEvent, "") | ||
} | ||
|
||
// newKeepaliveMessage is a convenience method to create a keepalive message | ||
func newKeepaliveMessage() *message { | ||
return newMessage(keepaliveEvent, "") | ||
} | ||
|
||
// newDefaultMessage is a convenience method to create a notification message | ||
func newDefaultMessage(msg string) *message { | ||
return newMessage("", msg) | ||
} |
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