Implement event stream
This commit is contained in:
1 parent
f90063cb03
commit
80a99c425b
24 files changed
+697
-113
No files matched your search
@@ -10,6 +10,7 @@ type Backend struct {
|
||||
Address string `json:"address"`
|
||||
Version string `json:"version"`
|
||||
LibVersion string `json:"lib_version"`
|
||||
ModuleName string `json:"module_name"`
|
||||
Endpoints xtypes.Json[[]cluster.EndpointDescriptor] `json:"endpoints"`
|
||||
RequiredModules xtypes.Json[[]cluster.ModuleDependency] `json:"required_modules"`
|
||||
CreatedAt xtypes.Time `json:"created_at"`
|
||||
|
||||
+16
-3
@@ -1,6 +1,8 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"isp-config-service/entity/xtypes"
|
||||
)
|
||||
|
||||
@@ -15,19 +17,30 @@ const (
|
||||
|
||||
type Event struct {
|
||||
RowId int `json:"rowid"`
|
||||
Type EventType `json:"type"`
|
||||
Payload xtypes.Json[EventPayload] `json:"payload"`
|
||||
}
|
||||
|
||||
func NewEvent(t EventType, payload EventPayload) Event {
|
||||
func NewEvent(payload EventPayload) Event {
|
||||
return Event{
|
||||
Type: t,
|
||||
Payload: xtypes.Json[EventPayload]{
|
||||
Value: payload,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (e Event) Key() string {
|
||||
switch {
|
||||
case e.Payload.Value.ConfigUpdated != nil:
|
||||
return fmt.Sprintf("config_updated_%s", e.Payload.Value.ConfigUpdated.ModuleId)
|
||||
case e.Payload.Value.ModuleReady != nil:
|
||||
return fmt.Sprintf("module_lifecycle_%s", e.Payload.Value.ModuleReady.ModuleId)
|
||||
case e.Payload.Value.ModuleDisconnected != nil:
|
||||
return fmt.Sprintf("module_lifecycle_%s", e.Payload.Value.ModuleDisconnected.ModuleId)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
type EventPayload struct {
|
||||
ConfigUpdated *PayloadConfigUpdated `json:",omitempty"`
|
||||
ModuleReady *PayloadModuleReady `json:",omitempty"`
|
||||
|
||||
Reference in new issue
Block a user