-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
58 lines (48 loc) · 1.02 KB
/
store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package store
import (
"errors"
"fmt"
)
// ErrNotFound is a standard not found error
var (
ErrNotFound = errors.New("not found")
)
type ErrorType int
type ErrorOp int
const (
ErrorTypeNone ErrorType = iota
ErrorTypeIncomplete
ErrorTypeForeignKey
ErrorTypeDuplicate
ErrorTypeInvalid
ErrorTypeQuery
ErrorOpSave ErrorOp = iota
ErrorOpGet
ErrorOpDelete
ErrorOpFind
)
type Error struct {
Type ErrorType
Err error
}
func (e *Error) Error() string { return e.Err.Error() }
func (e *Error) Unwrap() error { return e.Err }
func (e *Error) ErrorForOp(op ErrorOp) error {
switch e.Type {
case ErrorTypeNone:
return nil
case ErrorTypeIncomplete:
return fmt.Errorf("missing data: %w", e.Err)
case ErrorTypeForeignKey:
return fmt.Errorf("foreign key: %w", e.Err)
case ErrorTypeDuplicate:
return fmt.Errorf("duplicate: %w", e.Err)
case ErrorTypeInvalid:
return fmt.Errorf("invalid data: %w", e.Err)
}
return e.Err
}
type Results struct {
Count int64 `json:"count"`
Results interface{} `json:"results"`
}