feat(domain): add idempotency scope, result and conflict error
This commit is contained in:
@@ -49,6 +49,17 @@ func (e *AlreadyExistsError) Error() string {
|
|||||||
func (e *AlreadyExistsError) Unwrap() error { return ErrAlreadyExists }
|
func (e *AlreadyExistsError) Unwrap() error { return ErrAlreadyExists }
|
||||||
func (e *AlreadyExistsError) Code() ErrorCode { return CodeConflict }
|
func (e *AlreadyExistsError) Code() ErrorCode { return CodeConflict }
|
||||||
|
|
||||||
|
type IdempotencyConflictError struct {
|
||||||
|
Key string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *IdempotencyConflictError) Error() string {
|
||||||
|
return "Idempotency-Key " + e.Key + " уже использован с другим телом запроса"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *IdempotencyConflictError) Unwrap() error { return ErrAlreadyExists }
|
||||||
|
func (e *IdempotencyConflictError) Code() ErrorCode { return CodeConflict }
|
||||||
|
|
||||||
type ValidationError struct {
|
type ValidationError struct {
|
||||||
Field string
|
Field string
|
||||||
Message string
|
Message string
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package domain
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IdempotencyScope struct {
|
||||||
|
UserID string
|
||||||
|
Method string
|
||||||
|
Path string
|
||||||
|
Key string
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateIdempotentResult struct {
|
||||||
|
Status int
|
||||||
|
Body []byte
|
||||||
|
Replayed bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func RequestHash(text string) []byte {
|
||||||
|
sum := sha256.Sum256([]byte(text))
|
||||||
|
return sum[:]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user