add internal/{processor,streaming}
This commit is contained in:
parent
6f17b59a47
commit
5c6da51234
6 changed files with 128 additions and 29 deletions
57
internal/streaming/event.go
Normal file
57
internal/streaming/event.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
package streaming
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type EventType int8
|
||||
|
||||
const (
|
||||
EventTypeError EventType = 1
|
||||
EventTypePost EventType = 2
|
||||
|
||||
EventTypeSubscribe EventType = 126
|
||||
EventTypeUnsubscribe EventType = 127
|
||||
)
|
||||
|
||||
func (et EventType) Valid() bool {
|
||||
switch et {
|
||||
case EventTypeError:
|
||||
return true
|
||||
case EventTypePost:
|
||||
return true
|
||||
case EventTypeSubscribe:
|
||||
return true
|
||||
case EventTypeUnsubscribe:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true if this event can be subscribed to/unsubscribed from
|
||||
func (et EventType) ValidReceive() bool {
|
||||
if !et.Valid() {
|
||||
return false
|
||||
}
|
||||
|
||||
switch et {
|
||||
case EventTypeError, EventTypeSubscribe, EventTypeUnsubscribe:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
Type EventType `json:"t"`
|
||||
Data any `json:"d"`
|
||||
}
|
||||
|
||||
type ErrorEvent struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type IncomingEvent struct {
|
||||
Type EventType `json:"t"`
|
||||
Data json.RawMessage `json:"d"` // this is a RawMessage so we can easily unmarshal it later
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue