Use sentinel value

This commit is contained in:
Fedor Korotkiy 2020-03-11 16:17:13 +03:00
parent bba7be641a
commit 743b41e359
2 changed files with 5 additions and 11 deletions

View file

@ -3,6 +3,7 @@
package kvapi package kvapi
import ( import (
"errors"
"fmt" "fmt"
"github.com/gofrs/uuid" "github.com/gofrs/uuid"
@ -12,9 +13,10 @@ var (
_ error = (*APIError)(nil) _ error = (*APIError)(nil)
_ error = (*ConflictError)(nil) _ error = (*ConflictError)(nil)
_ error = (*AuthError)(nil) _ error = (*AuthError)(nil)
_ error = (*NotFoundError)(nil)
) )
var ErrKeyNotFound = errors.New("key not found")
type ( type (
APIError struct { APIError struct {
Method string Method string
@ -29,10 +31,6 @@ type (
AuthError struct { AuthError struct {
Msg string Msg string
} }
NotFoundError struct {
Key string
}
) )
func (a *APIError) Error() string { func (a *APIError) Error() string {
@ -50,7 +48,3 @@ func (a *ConflictError) Error() string {
func (a *AuthError) Error() string { func (a *AuthError) Error() string {
return fmt.Sprintf("api: auth: %s", a.Msg) return fmt.Sprintf("api: auth: %s", a.Msg)
} }
func (a *NotFoundError) Error() string {
return fmt.Sprintf("api: key %q is not found", a.Key)
}

View file

@ -31,8 +31,8 @@ var (
errGetAuth = &kvapi.APIError{Method: "get", Err: &kvapi.AuthError{Msg: "token expired"}} errGetAuth = &kvapi.APIError{Method: "get", Err: &kvapi.AuthError{Msg: "token expired"}}
errSetAuth = &kvapi.APIError{Method: "set", Err: &kvapi.AuthError{Msg: "token expired"}} errSetAuth = &kvapi.APIError{Method: "set", Err: &kvapi.AuthError{Msg: "token expired"}}
errGetNoKey = &kvapi.APIError{Method: "get", Err: &kvapi.NotFoundError{Key: K0}} errGetNoKey = &kvapi.APIError{Method: "get", Err: kvapi.ErrKeyNotFound}
errSetNoKey = &kvapi.APIError{Method: "set", Err: &kvapi.NotFoundError{Key: K0}} errSetNoKey = &kvapi.APIError{Method: "set", Err: kvapi.ErrKeyNotFound}
errGetTemporary = &kvapi.APIError{Method: "get", Err: errors.New("unavailable")} errGetTemporary = &kvapi.APIError{Method: "get", Err: errors.New("unavailable")}
errSetTemporary = &kvapi.APIError{Method: "set", Err: errors.New("unavailable")} errSetTemporary = &kvapi.APIError{Method: "set", Err: errors.New("unavailable")}