mirror of
https://codeberg.org/superseriousbusiness/gotosocial.git
synced 2024-12-25 10:28:18 +03:00
a684fc4628
* improve error readability, mark "bad hosts" as fastFail Signed-off-by: kim <grufwub@gmail.com> * pull in latest go-byteutil version with byteutil.Reader{} Signed-off-by: kim <grufwub@gmail.com> * use rewindable body reader for post requests Signed-off-by: kim <grufwub@gmail.com> --------- Signed-off-by: kim <grufwub@gmail.com>
36 lines
692 B
Go
36 lines
692 B
Go
package byteutil
|
|
|
|
import "bytes"
|
|
|
|
// Reader wraps a bytes.Reader{} to provide Rewind() capabilities.
|
|
type Reader struct {
|
|
B []byte
|
|
bytes.Reader
|
|
}
|
|
|
|
// NewReader returns a new Reader{} instance reset to b.
|
|
func NewReader(b []byte) *Reader {
|
|
r := &Reader{}
|
|
r.Reset(b)
|
|
return r
|
|
}
|
|
|
|
// Reset resets the Reader{} to be reading from b and sets Reader{}.B.
|
|
func (r *Reader) Reset(b []byte) {
|
|
r.B = b
|
|
r.Rewind()
|
|
}
|
|
|
|
// Rewind resets the Reader{} to be reading from the start of Reader{}.B.
|
|
func (r *Reader) Rewind() {
|
|
r.Reader.Reset(r.B)
|
|
}
|
|
|
|
// ReadNopCloser wraps a Reader{} to provide nop close method.
|
|
type ReadNopCloser struct {
|
|
Reader
|
|
}
|
|
|
|
func (*ReadNopCloser) Close() error {
|
|
return nil
|
|
}
|