mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-08 16:22:46 +01:00
33
bus/result.go
Normal file
33
bus/result.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package bus
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
emitter "github.com/emitter-io/go/v2"
|
||||
|
||||
"github.com/SecurityBrewery/catalyst/generated/models"
|
||||
)
|
||||
|
||||
const channelResult = "result"
|
||||
|
||||
type ResultMsg struct {
|
||||
Automation string `json:"automation"`
|
||||
Data map[string]interface{} `json:"data,omitempty"`
|
||||
Target *models.Origin `json:"target"`
|
||||
}
|
||||
|
||||
func (b *Bus) PublishResult(automation string, data map[string]interface{}, target *models.Origin) error {
|
||||
return b.jsonPublish(&ResultMsg{Automation: automation, Data: data, Target: target}, channelResult, b.config.resultBusKey)
|
||||
}
|
||||
|
||||
func (b *Bus) SubscribeResult(f func(msg *ResultMsg)) error {
|
||||
return b.safeSubscribe(b.config.resultBusKey, channelResult, func(c *emitter.Client, m emitter.Message) {
|
||||
var msg ResultMsg
|
||||
if err := json.Unmarshal(m.Payload(), &msg); err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
go f(&msg)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user