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()) } }