mirror of
https://github.com/openziti/ziti.git
synced 2026-09-10 08:45:41 +00:00
1c122af490
- moves the channel dependency to channel/v5 v5.0.10 and sdk-golang to v1.9.0 in the root and zititest modules - mechanically rewrites every channel/v4 import path to channel/v5 This is the import-path-only step; the API-level changes the switch requires land in the following commit. This commit does not build on its own.
61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
package handler_common
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/michaelquigley/pfxlog"
|
|
"github.com/openziti/channel/v5"
|
|
"github.com/openziti/ziti/v2/common/ctrl_msg"
|
|
)
|
|
|
|
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")
|
|
}
|
|
}
|
|
|
|
func SendServerBusy(request *channel.Message, ch channel.Channel, op string) {
|
|
log := pfxlog.ContextLogger(ch.Label()).WithField("operation", op)
|
|
log.Errorf("%v error performing %v: (%s)", ch.LogicalName(), op, "server too busy")
|
|
|
|
response := channel.NewResult(false, "server too busy")
|
|
response.ReplyTo(request)
|
|
response.Headers.PutUint32Header(ctrl_msg.HeaderResultErrorCode, ctrl_msg.ResultErrorRateLimited)
|
|
if err := response.WithTimeout(5 * time.Second).SendAndWaitForWire(ch); err != nil {
|
|
log.WithError(err).Error("failed to send result")
|
|
}
|
|
}
|
|
|
|
func WasRateLimited(msg *channel.Message) bool {
|
|
val, found := msg.GetUint32Header(ctrl_msg.HeaderResultErrorCode)
|
|
return found && val == ctrl_msg.ResultErrorRateLimited
|
|
}
|