2020-03-07 19:14:49 +00:00
|
|
|
// +build !change
|
|
|
|
|
|
|
|
package kvapi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/gofrs/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-03-07 19:15:30 +00:00
|
|
|
_ error = (*APIError)(nil)
|
2020-03-07 19:14:49 +00:00
|
|
|
_ error = (*ConflictError)(nil)
|
|
|
|
_ error = (*AuthError)(nil)
|
|
|
|
_ error = (*NotFoundError)(nil)
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
2020-03-07 19:15:30 +00:00
|
|
|
APIError struct {
|
2020-03-07 19:14:49 +00:00
|
|
|
Method string
|
|
|
|
|
|
|
|
Err error
|
|
|
|
}
|
|
|
|
|
|
|
|
ConflictError struct {
|
|
|
|
ProvidedVersion, ExpectedVersion uuid.UUID
|
|
|
|
}
|
|
|
|
|
|
|
|
AuthError struct {
|
|
|
|
Msg string
|
|
|
|
}
|
|
|
|
|
|
|
|
NotFoundError struct {
|
|
|
|
Key string
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-03-07 19:15:30 +00:00
|
|
|
func (a *APIError) Error() string {
|
2020-03-07 19:14:49 +00:00
|
|
|
return fmt.Sprintf("api: %q error: %v", a.Method, a.Err)
|
|
|
|
}
|
|
|
|
|
2020-03-07 19:15:30 +00:00
|
|
|
func (a *APIError) Unwrap() error {
|
2020-03-07 19:14:49 +00:00
|
|
|
return a.Err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *ConflictError) Error() string {
|
|
|
|
return fmt.Sprintf("api: conflict: expected_version=%d, provided_version=%d", a.ExpectedVersion, a.ProvidedVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AuthError) Error() string {
|
|
|
|
return fmt.Sprintf("api: auth: %s", a.Msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *NotFoundError) Error() string {
|
|
|
|
return fmt.Sprintf("api: key %q is not found", a.Key)
|
|
|
|
}
|