Documentation ¶
Index ¶
- Constants
- Variables
- func NewLimitsError(message string, args ...interface{}) error
- func ReadAll(reader io.Reader, limit int64) ([]byte, error)
- func TrackCost(ctx context.Context, cost int) error
- func WithLimits(ctx context.Context, l Limits) context.Context
- type Limits
- type LimitsError
- type Option
- type StandardLimits
- func (l *StandardLimits) IOTimeout() time.Duration
- func (l *StandardLimits) MaxBufferSize() int64
- func (l *StandardLimits) ReadAll(reader io.Reader) ([]byte, error)
- func (l *StandardLimits) TrackCost(cost int) error
- func (l *StandardLimits) TrackHTTPRequest(req *http.Request) error
- func (l *StandardLimits) TrackHTTPResponse(resp *http.Response) error
Constants ¶
const NoLimit = -1
Variables ¶
var LimitsNotFound = NewLimitsError("limit error: limits not found in context")
LimitsNotFound is a standard error that indicates limits were expected to be present in a context, but were not found.
Functions ¶
func NewLimitsError ¶
NewLimitsError returns a new LimitsError with the given message.
func ReadAll ¶
ReadAll reads from the given reader until EOF or the limit is reached. If the given limit is less than zero, the entire reader is read.
Types ¶
type Limits ¶
type Limits interface { // IOTimeout returns the maximum amount of time to wait for IO operations. IOTimeout() time.Duration // MaxBodySize returns the maximum allowed size buffer in bytes. This is // relevant for any buffered I/O operation, e.g. reading an HTTP request body. MaxBufferSize() int64 // TrackHTTPRequest returns an error if the HTTP request should not // be processed due to exceeding a limit. TrackHTTPRequest(*http.Request) error // TrackHTTPResponse returns an error if the HTTP response should not // be processed due to exceeding a body or content length limit. TrackHTTPResponse(*http.Response) error // TrackCost returns an error if the given incremental processing cost // causes the cost limit to be exceeded. TrackCost(cost int) error // ReadAll reads from the given reader until EOF or a limit is reached. // This counts towards the allocation limit. ReadAll(reader io.Reader) ([]byte, error) }
type LimitsError ¶
type LimitsError struct {
// contains filtered or unexported fields
}
LimitsError indicates that a limit was exceeded.
func (*LimitsError) Error ¶
func (e *LimitsError) Error() string
type Option ¶
type Option func(*StandardLimits)
Option is a function that configures a Limits instance.
func WithIOTimeout ¶
WithIOTimeout sets the maximum amount of time to wait for IO operations.
func WithMaxBufferSize ¶
WithMaxBufferSize sets the maximum allowed size buffer in bytes. This is relevant for any buffered I/O operation, e.g. reading an HTTP request body.
func WithMaxCost ¶
WithMaxCost sets the maximum number allowed processing cost.
func WithMaxHttpRequestCount ¶
WithMaxHttpRequestCount sets the maximum number of HTTP requests that are allowed to be processed.
type StandardLimits ¶
type StandardLimits struct {
// contains filtered or unexported fields
}
func (*StandardLimits) IOTimeout ¶
func (l *StandardLimits) IOTimeout() time.Duration
func (*StandardLimits) MaxBufferSize ¶
func (l *StandardLimits) MaxBufferSize() int64
func (*StandardLimits) TrackCost ¶
func (l *StandardLimits) TrackCost(cost int) error
func (*StandardLimits) TrackHTTPRequest ¶
func (l *StandardLimits) TrackHTTPRequest(req *http.Request) error
func (*StandardLimits) TrackHTTPResponse ¶
func (l *StandardLimits) TrackHTTPResponse(resp *http.Response) error