Documentation
¶
Index ¶
- func ProgressReader(reader io.Reader, total int64, onProgress func(read, total int64)) *progressReader
- func ProgressWriter(writer io.WriteCloser, total int64, onProgress func(written, total int64)) *progressWriter
- type CompressionType
- type Option
- func (opt *Option) AddCookie(cookie *http.Cookie)
- func (opt *Option) AddHeader(key string, value string)
- func (opt *Option) ClearCookies()
- func (opt *Option) ClearHeaders()
- func (opt *Option) DisableLogging()
- func (opt *Option) DisablePreserveMethodOnRedirect()
- func (opt *Option) DisableRedirects()
- func (opt *Option) EnableLogging()
- func (opt *Option) EnablePreserveMethodOnRedirect()
- func (opt *Option) EnableRedirects()
- func (opt *Option) GenerateIdentifier() string
- func (opt *Option) GetCompressor(w *io.PipeWriter) (io.WriteCloser, error)
- func (opt *Option) GetWriter() io.WriteCloser
- func (opt *Option) InitialiseWriter() (io.WriteCloser, error)
- func (opt *Option) ListCookies()
- func (opt *Option) ListHeaders()
- func (opt *Option) LogVerbose(msg string, args ...any)
- func (opt *Option) Merge(src *Option)
- func (opt *Option) SetBufferOutput()
- func (opt *Option) SetCompression(compressionType CompressionType)
- func (opt *Option) SetDownloadBufferSize(sizeInBytes int)
- func (opt *Option) SetFileOutput(filepath string)
- func (opt *Option) SetLogger(logger *slog.Logger)
- func (opt *Option) SetOutput(writerType ResponseWriterType, filepath ...string) error
- func (opt *Option) SetProtocolScheme(scheme string)
- func (opt *Option) SetTransport(transport *http.Transport)
- func (opt *Option) UseJsonLogger()
- func (opt *Option) UseTextLogger()
- type ResponseWriter
- type ResponseWriterType
- type UniqueIdentifierType
- type UploadType
- type WriteCloserBuffer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ProgressReader ¶
func ProgressWriter ¶
func ProgressWriter(writer io.WriteCloser, total int64, onProgress func(written, total int64)) *progressWriter
ProgressWriter creates a new ProgressWriter
Types ¶
type CompressionType ¶
type CompressionType string
const ( CompressionNone CompressionType = "" CompressionGzip CompressionType = "gzip" CompressionDeflate CompressionType = "deflate" CompressionBrotli CompressionType = "br" CompressionCustom CompressionType = "custom" )
type Option ¶
type Option struct {
Verbose bool // Whether logging should be verbose or not
Logger slog.Logger // Logging - default uses the slog TextHandler
Header http.Header // Headers to be included in the request
Cookies []*http.Cookie // Cookies to be included in the request
ProtocolScheme string // define a custom protocol scheme. It defaults to https
Compression CompressionType // CompressionType to use: none, gzip, deflate or brotli
CustomCompressionType CompressionType //
CustomCompressor func(w *io.PipeWriter) (io.WriteCloser, error) // Function for custom compression
UserAgent string // User Agent to send with requests
FollowRedirect bool // Disable or enable redirects. Default is true i.e.: follow redirects
PreserveMethodOnRedirect bool // Default is true
UniqueIdentifierType UniqueIdentifierType // Internal trace or identifier for the request
Transport *http.Transport // Create our own default transport
ResponseWriter ResponseWriter // Define the type of response writer
UploadBufferSize *int // Control the size of the buffer when uploading a file
DownloadBufferSize *int // Control the size of the buffer when downloading a file
OnUploadProgress func(bytesRead, totalBytes int64) // To monitor and track progress when uploading
OnDownloadProgress func(bytesRead, totalBytes int64) // To monitor and track progress when downloading
}
RequestOptions represents additional options for the HTTP request. DisableRedirect - Determines if redirects should be followed or not. The default option is false which means redirects will be followed.
func (*Option) ClearCookies ¶
func (opt *Option) ClearCookies()
ClearCookies clears all cookies in the RequestOptions.
func (*Option) ClearHeaders ¶
func (opt *Option) ClearHeaders()
ClearHeaders clears all headers in the RequestOptions.
func (*Option) DisableLogging ¶
func (opt *Option) DisableLogging()
func (*Option) DisablePreserveMethodOnRedirect ¶
func (opt *Option) DisablePreserveMethodOnRedirect()
func (*Option) DisableRedirects ¶
func (opt *Option) DisableRedirects()
func (*Option) EnableLogging ¶
func (opt *Option) EnableLogging()
func (*Option) EnablePreserveMethodOnRedirect ¶
func (opt *Option) EnablePreserveMethodOnRedirect()
func (*Option) EnableRedirects ¶
func (opt *Option) EnableRedirects()
func (*Option) GenerateIdentifier ¶
func (*Option) GetCompressor ¶
func (opt *Option) GetCompressor(w *io.PipeWriter) (io.WriteCloser, error)
func (*Option) GetWriter ¶
func (opt *Option) GetWriter() io.WriteCloser
GetWriter returns the underlying io.WriteCloser
func (*Option) InitialiseWriter ¶
func (opt *Option) InitialiseWriter() (io.WriteCloser, error)
InitialiseWriter sets up the appropriate writer based on the ResponseWriter configuration
func (*Option) ListCookies ¶
func (opt *Option) ListCookies()
ListCookies prints out the list of cookies in the RequestOptions.
func (*Option) ListHeaders ¶
func (opt *Option) ListHeaders()
ListHeaders prints out the list of headers in the RequestOptions.
func (*Option) LogVerbose ¶
func (*Option) SetBufferOutput ¶
func (opt *Option) SetBufferOutput()
SetBufferOutput configures the response writer to write to an in-memory buffer
func (*Option) SetCompression ¶
func (opt *Option) SetCompression(compressionType CompressionType)
func (*Option) SetDownloadBufferSize ¶
SetDownloadBufferSize allows custom buffer size if needed
func (*Option) SetFileOutput ¶
SetFileOutput configures the response writer to write to a file
func (*Option) SetOutput ¶
func (opt *Option) SetOutput(writerType ResponseWriterType, filepath ...string) error
SetOutput configures how the response should be written For WriteToBuffer: opt.SetOutput(WriteToBuffer) For WriteToFile: opt.SetOutput(WriteToFile, "path/to/file.txt")
func (*Option) SetProtocolScheme ¶
func (*Option) SetTransport ¶
func (*Option) UseJsonLogger ¶
func (opt *Option) UseJsonLogger()
func (*Option) UseTextLogger ¶
func (opt *Option) UseTextLogger()
type ResponseWriter ¶
type ResponseWriter struct {
// Type indicates whether to write to buffer or file
Type ResponseWriterType
// FilePath is only used when Type is WriteToFile
FilePath string
// contains filtered or unexported fields
}
ResponseWriter contains configuration for how to handle the HTTP response body
type ResponseWriterType ¶
type ResponseWriterType string
const ( WriteToBuffer ResponseWriterType = "buffer" WriteToFile ResponseWriterType = "file" )
type UniqueIdentifierType ¶
type UniqueIdentifierType string
const ( IdentifierNone UniqueIdentifierType = "" IdentifierUUID UniqueIdentifierType = "uuid" IdentifierULID UniqueIdentifierType = "ulid" )
type UploadType ¶
type UploadType string
type WriteCloserBuffer ¶
func (*WriteCloserBuffer) Close ¶
func (wcb *WriteCloserBuffer) Close() error