-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from caesarxuchao/limit-total-copy-size
Limiting the total copy size
- Loading branch information
Showing
4 changed files
with
109 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package jsonpatch | ||
|
||
import "fmt" | ||
|
||
// AccumulatedCopySizeError is an error type returned when the accumulated size | ||
// increase caused by copy operations in a patch operation has exceeded the | ||
// limit. | ||
type AccumulatedCopySizeError struct { | ||
limit int64 | ||
accumulated int64 | ||
} | ||
|
||
// NewAccumulatedCopySizeError returns an AccumulatedCopySizeError. | ||
func NewAccumulatedCopySizeError(l, a int64) *AccumulatedCopySizeError { | ||
return &AccumulatedCopySizeError{limit: l, accumulated: a} | ||
} | ||
|
||
// Error implements the error interface. | ||
func (a *AccumulatedCopySizeError) Error() string { | ||
return fmt.Sprintf("Unable to complete the copy, the accumulated size increase of copy is %d, exceeding the limit %d", a.accumulated, a.limit) | ||
} | ||
|
||
// ArraySizeError is an error type returned when the array size has exceeded | ||
// the limit. | ||
type ArraySizeError struct { | ||
limit int | ||
size int | ||
} | ||
|
||
// NewArraySizeError returns an ArraySizeError. | ||
func NewArraySizeError(l, s int) *ArraySizeError { | ||
return &ArraySizeError{limit: l, size: s} | ||
} | ||
|
||
// Error implements the error interface. | ||
func (a *ArraySizeError) Error() string { | ||
return fmt.Sprintf("Unable to create array of size %d, limit is %d", a.size, a.limit) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters