Documentation ¶
Overview ¶
Package util provides general helpers used by Relay code.
Index ¶
- func DecompressGzipData(data []byte) ([]byte, error)
- func ErrorJSONMsg(msg string) (j []byte)
- func ErrorJSONMsgf(fmtStr string, args ...interface{}) []byte
- func NewReader(r io.ReadCloser, isGzipped bool, maxInboundPayloadSize ct.OptBase2Bytes) (io.ReadCloser, error)
- func RedactURL(inputURL string) string
- type CleanupTasks
- type PayloadReader
- type StringMemoizer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecompressGzipData ¶ added in v8.9.0
func ErrorJSONMsg ¶
ErrorJSONMsg returns a json-encoded error message
func ErrorJSONMsgf ¶
ErrorJSONMsgf returns a json-encoded error message using the printf formatter
func NewReader ¶ added in v8.9.0
func NewReader(r io.ReadCloser, isGzipped bool, maxInboundPayloadSize ct.OptBase2Bytes) (io.ReadCloser, error)
NewReader creates a new reader
Types ¶
type CleanupTasks ¶
type CleanupTasks []func()
CleanupTasks accumulates a list of things which should be done at the end of a method unless Clear() is called. Intended usage:
var cleanup CleanupTasks defer cleanup.Run() thing1 := createThing1() cleanup.AddCloser(thing1) err := doSomethingElse() if err != nil { return err // thing1 will be disposed of automatically } cleanup.Clear() // everything succeeded so we don't want thing1 to be disposed of
func (*CleanupTasks) AddCloser ¶
func (t *CleanupTasks) AddCloser(c io.Closer)
AddCloser adds a task for calling Close on an object
type PayloadReader ¶ added in v8.9.0
type PayloadReader struct { IsGzipped bool MaxBytes int64 // contains filtered or unexported fields }
PayloadReader is an implementation of io.Reader that reads bytes off the request body optionally decompresses them, and has a limit attached. If the limit is reached, an error will be returned and the underlying stream will be closed.
Note: limit is applied to *both* compressed and uncompressed number of bytes. This protects us from potential zipbombs
func (*PayloadReader) Close ¶ added in v8.9.0
func (pr *PayloadReader) Close() error
func (*PayloadReader) GetBytesRead ¶ added in v8.9.0
func (pr *PayloadReader) GetBytesRead() int64
GetBytesRead returns the total number of bytes read off the original stream
func (*PayloadReader) GetUncompressedBytesRead ¶ added in v8.9.0
func (pr *PayloadReader) GetUncompressedBytesRead() int64
GetUncompressedBytesRead Total number of Bytes in the uncompressed stream.
GetBytesRead and GetUncompressedBytesRead will return the same value if the stream is uncompressed.
type StringMemoizer ¶
type StringMemoizer struct {
// contains filtered or unexported fields
}
StringMemoizer is a simple encapsulation of a lazily evaluated-only-once string function.
func NewStringMemoizer ¶
func NewStringMemoizer(computeFn func() string) *StringMemoizer
NewStringMemoizer creates a new uninitialized StringMemoizer.
func (*StringMemoizer) Get ¶
func (m *StringMemoizer) Get() string
Get returns the result of the computeFn, calling it only if it has not already been called.