mirror of
https://github.com/openziti/ziti.git
synced 2026-09-25 11:57:28 +00:00
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package handler_common
|
|
|
|
import (
|
|
"github.com/michaelquigley/pfxlog"
|
|
"github.com/openziti/channel/v2"
|
|
"time"
|
|
)
|
|
|
|
func SendSuccess(request *channel.Message, ch channel.Channel, message string) {
|
|
SendResult(request, ch, message, true)
|
|
}
|
|
|
|
func SendFailure(request *channel.Message, ch channel.Channel, message string) {
|
|
SendResult(request, ch, message, false)
|
|
}
|
|
|
|
func SendResult(request *channel.Message, ch channel.Channel, message string, success bool) {
|
|
log := pfxlog.ContextLogger(ch.Label())
|
|
if !success {
|
|
log.Errorf("%v error (%s)", ch.LogicalName(), message)
|
|
}
|
|
|
|
response := channel.NewResult(success, message)
|
|
response.ReplyTo(request)
|
|
if err := response.WithTimeout(5 * time.Second).SendAndWaitForWire(ch); err != nil {
|
|
log.WithError(err).Error("failed to send result")
|
|
}
|
|
}
|
|
|
|
func SendOpResult(request *channel.Message, ch channel.Channel, op string, message string, success bool) {
|
|
log := pfxlog.ContextLogger(ch.Label()).WithField("operation", op)
|
|
if !success {
|
|
log.Errorf("%v error performing %v: (%s)", ch.LogicalName(), op, message)
|
|
}
|
|
|
|
response := channel.NewResult(success, message)
|
|
response.ReplyTo(request)
|
|
if err := response.WithTimeout(5 * time.Second).SendAndWaitForWire(ch); err != nil {
|
|
log.WithError(err).Error("failed to send result")
|
|
}
|
|
}
|