Adam Štrauch
e58d6462a9
All checks were successful
continuous-integration/drone/push Build is passing
Taking logic from handler into glue module Add tests for apps Updated docker library
52 lines
904 B
Go
52 lines
904 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/nats-io/nats.go"
|
|
)
|
|
|
|
func errorReplyFormater(m *nats.Msg, message string, err error) error {
|
|
reply := ReplyMessage{
|
|
Error: true,
|
|
Payload: message,
|
|
}
|
|
|
|
log.Println("ERROR:", err.Error())
|
|
|
|
data, err := json.Marshal(reply)
|
|
if err != nil {
|
|
log.Println("ERROR:", err.Error())
|
|
return err
|
|
}
|
|
|
|
err = m.Respond(data)
|
|
if err != nil {
|
|
log.Println("ERROR:", err.Error())
|
|
return err
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func publish(appName string, state string, isErr bool) {
|
|
stateMessage := StateMessage{
|
|
AppName: appName,
|
|
Error: isErr,
|
|
Message: state,
|
|
}
|
|
|
|
data, err := stateMessage.JSON()
|
|
if err != nil {
|
|
log.Println("ERROR: publish:", err.Error())
|
|
}
|
|
|
|
subjectEvents := fmt.Sprintf("admin.apps.%s.states", config.NATSAlias)
|
|
err = nc.Publish(subjectEvents, data)
|
|
if err != nil {
|
|
log.Println("ERROR: publish:", err.Error())
|
|
}
|
|
}
|