feat: reimplement influx backup using new APIs (#116)

This commit is contained in:
Daniel Moran
2021-06-11 09:50:39 -04:00
committed by GitHub
parent ea2cbab67b
commit 943e8fba31
17 changed files with 1462 additions and 50 deletions

View File

@ -5,6 +5,11 @@ import (
"strings"
)
type ApiError interface {
error
ErrorCode() ErrorCode
}
// Extensions to let our API error types be used as "standard" errors.
func (o *Error) Error() string {
@ -22,6 +27,10 @@ func (o *Error) Error() string {
return fmt.Sprintf("<%s>", o.Code)
}
func (o *Error) ErrorCode() ErrorCode {
return o.Code
}
func (o *HealthCheck) Error() string {
if o.Status == HEALTHCHECKSTATUS_PASS {
// Make sure we aren't misusing HealthCheck responses.
@ -36,10 +45,47 @@ func (o *HealthCheck) Error() string {
return fmt.Sprintf("health check failed: %s", message)
}
func (o *HealthCheck) ErrorCode() ErrorCode {
if o.Status == HEALTHCHECKSTATUS_PASS {
// Make sure we aren't misusing HealthCheck responses.
panic("successful healthcheck used as an error!")
}
return ERRORCODE_INTERNAL_ERROR
}
func (o *LineProtocolError) Error() string {
return o.Message
}
func (o *LineProtocolError) ErrorCode() ErrorCode {
switch o.Code {
case LINEPROTOCOLERRORCODE_CONFLICT:
return ERRORCODE_CONFLICT
case LINEPROTOCOLERRORCODE_EMPTY_VALUE:
return ERRORCODE_EMPTY_VALUE
case LINEPROTOCOLERRORCODE_NOT_FOUND:
return ERRORCODE_NOT_FOUND
case LINEPROTOCOLERRORCODE_UNAVAILABLE:
return ERRORCODE_UNAVAILABLE
case LINEPROTOCOLERRORCODE_INTERNAL_ERROR:
return ERRORCODE_INTERNAL_ERROR
case LINEPROTOCOLERRORCODE_INVALID:
fallthrough
default:
return ERRORCODE_INVALID
}
}
func (o *LineProtocolLengthError) Error() string {
return o.Message
}
func (o *LineProtocolLengthError) ErrorCode() ErrorCode {
switch o.Code {
case LINEPROTOCOLLENGTHERRORCODE_INVALID:
fallthrough
default:
return ERRORCODE_INVALID
}
}