Documentation
¶
Overview ¶
Package client implements the internal HTTP request/response handling
Package client implements the internal HTTP request/response handling
Package client implements the internal HTTP request/response handling
Index ¶
- func Stream(r *Response, handler func([]byte) error, opts ...StreamOption) error
- func StreamInto(r *Response, handler interface{}, opts ...StreamOption) error
- func StreamJSON(r *Response, handler func(json.RawMessage) error, opts ...StreamOption) error
- func StreamLines(r *Response, handler func([]byte) error, opts ...StreamOption) error
- func StreamSSE(reader io.ReadCloser, handler EventSourceHandler) error
- type Event
- type EventFullHandlerFunc
- type EventHandlerFunc
- type EventSourceFullHandler
- type EventSourceHandler
- type HTTPClient
- type Request
- func (r *Request) Do(ctx context.Context) (*Response, error)
- func (r *Request) Stream(ctx context.Context, handler func([]byte) error, opts ...StreamOption) error
- func (r *Request) StreamInto(ctx context.Context, handler interface{}) error
- func (r *Request) StreamJSON(ctx context.Context, handler func(json.RawMessage) error) error
- func (r *Request) StreamLines(ctx context.Context, handler func([]byte) error, opts ...StreamOption) error
- func (r *Request) StreamSSE(ctx context.Context, handler EventSourceHandler) error
- func (r *Request) WithBody(body interface{}) *Request
- func (r *Request) WithHeader(key, value string) *Request
- func (r *Request) WithHeaders(headers map[string]string) *Request
- func (r *Request) WithMiddleware(m middleware.Middleware) *Request
- func (r *Request) WithMiddlewares(middlewares ...middleware.Middleware) *Request
- func (r *Request) WithQuery(key, value string) *Request
- func (r *Request) WithQueryMap(params map[string]string) *Request
- func (r *Request) WithTimeout(timeout time.Duration) *Request
- type Response
- func (r *Response) Bytes() ([]byte, error)
- func (r *Response) Close() error
- func (r *Response) Consume() error
- func (r *Response) IsClientError() bool
- func (r *Response) IsError() bool
- func (r *Response) IsRedirect() bool
- func (r *Response) IsServerError() bool
- func (r *Response) IsSuccess() bool
- func (r *Response) JSON(v interface{}) error
- func (r *Response) Pipe(ch chan<- []byte) error
- func (r *Response) Stream(handler func([]byte) error, opts ...StreamOption) error
- func (r *Response) StreamInto(handler interface{}, opts ...StreamOption) error
- func (r *Response) StreamJSON(handler func(json.RawMessage) error, opts ...StreamOption) error
- func (r *Response) StreamLines(handler func([]byte) error, opts ...StreamOption) error
- func (r *Response) StreamSSE(handler EventSourceHandler) error
- func (r *Response) String() (string, error)
- func (r *Response) WriteTo(w io.Writer) (int64, error)
- type StreamOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Stream ¶ added in v0.2.0
func Stream(r *Response, handler func([]byte) error, opts ...StreamOption) error
Stream processes a response stream with the provided handler function. The handler is called for each chunk of data. If the handler returns an error, streaming stops and the error is returned.
func StreamInto ¶ added in v0.2.0
func StreamInto(r *Response, handler interface{}, opts ...StreamOption) error
StreamInto processes a response stream as JSON objects and unmarshals each object into a new instance of the provided type, then passes it to the handler function.
func StreamJSON ¶ added in v0.2.0
func StreamJSON(r *Response, handler func(json.RawMessage) error, opts ...StreamOption) error
StreamJSON processes a response stream as JSON objects with the provided handler function. The handler is called for each JSON object. If the handler returns an error, streaming stops and the error is returned.
func StreamLines ¶ added in v0.2.0
func StreamLines(r *Response, handler func([]byte) error, opts ...StreamOption) error
StreamLines processes a response stream line by line with the provided handler function. The handler is called for each line. If the handler returns an error, streaming stops and the error is returned.
func StreamSSE ¶ added in v0.2.0
func StreamSSE(reader io.ReadCloser, handler EventSourceHandler) error
StreamSSE processes a Server-Sent Events stream with the provided handler.
Types ¶
type EventFullHandlerFunc ¶ added in v0.2.0
type EventFullHandlerFunc struct {
OnEventFunc func(event Event) error
OnOpenFunc func() error
OnCloseFunc func() error
}
EventFullHandlerFunc represents a function-based handler with lifecycle support
func (*EventFullHandlerFunc) OnClose ¶ added in v0.2.0
func (l *EventFullHandlerFunc) OnClose() error
OnClose implements EventSourceFullHandler interface
func (*EventFullHandlerFunc) OnEvent ¶ added in v0.2.0
func (l *EventFullHandlerFunc) OnEvent(event Event) error
OnEvent implements EventSourceHandler interface
func (*EventFullHandlerFunc) OnOpen ¶ added in v0.2.0
func (l *EventFullHandlerFunc) OnOpen() error
OnOpen implements EventSourceFullHandler interface
type EventHandlerFunc ¶ added in v0.2.0
EventHandlerFunc is a function type for handling SSE events
func (EventHandlerFunc) OnEvent ¶ added in v0.2.0
func (f EventHandlerFunc) OnEvent(event Event) error
OnEvent implements EventSourceHandler interface
type EventSourceFullHandler ¶ added in v0.2.0
type EventSourceFullHandler interface {
EventSourceHandler
OnOpen() error
OnClose() error
}
EventSourceFullHandler extends EventSourceHandler with lifecycle methods
type EventSourceHandler ¶ added in v0.2.0
EventSourceHandler handles incoming Server-Sent Events
type HTTPClient ¶ added in v0.2.0
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
GetMiddlewares() []middleware.Middleware
}
HTTPClient defines the interface for the HTTP client
type Request ¶
type Request struct {
Method string
URL string
Headers http.Header
Query url.Values
Body interface{}
Client HTTPClient
// contains filtered or unexported fields
}
Request represents a prepared HTTP request with middleware support
func (*Request) Stream ¶ added in v0.2.0
func (r *Request) Stream(ctx context.Context, handler func([]byte) error, opts ...StreamOption) error
Stream executes the request and streams the response as raw bytes
func (*Request) StreamInto ¶ added in v0.2.0
StreamInto executes the request and unmarshals each JSON object into the specified type
func (*Request) StreamJSON ¶ added in v0.2.0
StreamJSON executes the request and streams the response as JSON objects
func (*Request) StreamLines ¶ added in v0.2.0
func (r *Request) StreamLines(ctx context.Context, handler func([]byte) error, opts ...StreamOption) error
StreamLines executes the request and streams the response line by line
func (*Request) StreamSSE ¶ added in v0.2.0
func (r *Request) StreamSSE(ctx context.Context, handler EventSourceHandler) error
StreamSSE executes the request and streams the response as Server-Sent Events
func (*Request) WithHeader ¶
WithHeader sets a header for this request
func (*Request) WithHeaders ¶
WithHeaders sets multiple headers for this request
func (*Request) WithMiddleware ¶ added in v0.2.0
func (r *Request) WithMiddleware(m middleware.Middleware) *Request
WithMiddleware adds middleware specific to this request
func (*Request) WithMiddlewares ¶ added in v0.2.0
func (r *Request) WithMiddlewares(middlewares ...middleware.Middleware) *Request
WithMiddlewares adds multiple middlewares specific to this request
func (*Request) WithQueryMap ¶
WithQueryMap adds multiple query parameters to the request
type Response ¶
Response wraps the standard http.Response with additional utility methods
func (*Response) IsClientError ¶
IsClientError returns true if the status code is 4xx
func (*Response) IsError ¶ added in v0.2.0
IsError returns true if the status code indicates an error (4xx or 5xx)
func (*Response) IsRedirect ¶
IsRedirect returns true if the status code is 3xx
func (*Response) IsServerError ¶
IsServerError returns true if the status code is 5xx
func (*Response) Pipe ¶ added in v0.2.0
Pipe allows for piping the response body to the provided channel
func (*Response) Stream ¶ added in v0.2.0
func (r *Response) Stream(handler func([]byte) error, opts ...StreamOption) error
Stream processes a response stream with the provided handler function. The handler is called for each chunk of data.
func (*Response) StreamInto ¶ added in v0.2.0
func (r *Response) StreamInto(handler interface{}, opts ...StreamOption) error
StreamInto processes a response stream as JSON objects and unmarshals each object into a new instance of the provided type, then passes it to the handler function.
func (*Response) StreamJSON ¶ added in v0.2.0
func (r *Response) StreamJSON(handler func(json.RawMessage) error, opts ...StreamOption) error
StreamJSON processes a response stream as JSON objects with the provided handler function.
func (*Response) StreamLines ¶ added in v0.2.0
func (r *Response) StreamLines(handler func([]byte) error, opts ...StreamOption) error
StreamLines processes a response stream line by line with the provided handler function.
func (*Response) StreamSSE ¶ added in v0.2.0
func (r *Response) StreamSSE(handler EventSourceHandler) error
StreamSSE processes a Server-Sent Events stream with the provided handler function.
type StreamOption ¶ added in v0.2.0
type StreamOption func(*streamOptions)
StreamOption represents options for stream processing
func WithBufferSize ¶ added in v0.2.0
func WithBufferSize(size int) StreamOption
WithBufferSize sets the buffer size for stream reading
func WithByteDelimiter ¶ added in v0.2.0
func WithByteDelimiter(delimiter byte) StreamOption
WithByteDelimiter sets a byte delimiter for stream reading
func WithContentType ¶ added in v0.2.0
func WithContentType(contentType string) StreamOption
WithContentType sets the expected content type for the stream
func WithDelimiter ¶ added in v0.2.0
func WithDelimiter(delimiter string) StreamOption
WithDelimiter sets the delimiter for line-based stream reading