http package - github.com/gaussli/xii-go-http/pkg/http - Go Packages

http

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*XiiClient)

Option is a function that modifies the XiiClient.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets the base URL for the XiiClient.

func WithHeader

func WithHeader(key, value string) Option

WithHeader sets a header for the XiiClient.

func WithProxy

func WithProxy(proxyStr string) Option

WithProxy sets the proxy for the XiiClient.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the timeout for the XiiClient.

type XiiClient

type XiiClient struct {
	// contains filtered or unexported fields
}

XiiClient is a client for making HTTP requests.

func NewClient

func NewClient(opts ...Option) *XiiClient

NewClient creates a new XiiClient with the provided options.

func (*XiiClient) Do

func (c *XiiClient) Do(req *XiiRequest) (*XiiResponse, error)

Do sends an HTTP request and returns an HTTP response.

func (*XiiClient) Use

func (c *XiiClient) Use(mw XiiMiddleware)

Use adds a middleware to the XiiClient.

type XiiMiddleware

type XiiMiddleware func(*http.Request) error

XiiMiddleware is a function that modifies the HTTP request before it is sent.

type XiiRequest

type XiiRequest struct {
	// contains filtered or unexported fields
}

XiiRequest represents an HTTP request with various configurable options.

func NewXiiRequest

func NewXiiRequest() *XiiRequest

NewXiiRequest creates a new XiiRequest with default values.

func (*XiiRequest) Body

func (req *XiiRequest) Body(body io.Reader) *XiiRequest

Body sets the request body to the provided io.Reader.

func (*XiiRequest) Context

func (req *XiiRequest) Context(ctx context.Context) *XiiRequest

Context sets the request context.

func (*XiiRequest) DELETE

func (req *XiiRequest) DELETE(endpoint string) *XiiRequest

Shortcut methods for DELETE requests

func (*XiiRequest) Endpoint

func (req *XiiRequest) Endpoint(endpoint string) *XiiRequest

Endpoint sets the request endpoint.

func (*XiiRequest) FormBody

func (req *XiiRequest) FormBody(formData url.Values) *XiiRequest

FormBody sets the request body to the form-urlencoded representation of formData.

func (*XiiRequest) GET

func (req *XiiRequest) GET(endpoint string) *XiiRequest

Shortcut methods for GET requests

func (*XiiRequest) GetHeaders

func (req *XiiRequest) GetHeaders() map[string][]string

GetHeaders returns the headers of the request.

func (*XiiRequest) Header

func (req *XiiRequest) Header(key, value string) *XiiRequest

Header adds a header to the request.

func (*XiiRequest) JSONBody

func (req *XiiRequest) JSONBody(jsonData any) *XiiRequest

JSONBody sets the request body to the JSON representation of jsonData.

func (*XiiRequest) Method

func (req *XiiRequest) Method(method string) *XiiRequest

Method sets the request method.

func (*XiiRequest) MultipartFormBody

func (req *XiiRequest) MultipartFormBody(formData url.Values) *XiiRequest

MultipartFormBody sets the request body to the multipart form representation of formData.

func (*XiiRequest) PATCH

func (req *XiiRequest) PATCH(endpoint string) *XiiRequest

Shortcut methods for PATCH requests

func (*XiiRequest) POST

func (req *XiiRequest) POST(endpoint string) *XiiRequest

Shortcut methods for POST requests

func (*XiiRequest) PUT

func (req *XiiRequest) PUT(endpoint string) *XiiRequest

Shortcut methods for PUT requests

func (*XiiRequest) QueryParam

func (req *XiiRequest) QueryParam(key, value string) *XiiRequest

QueryParam adds a query parameter to the request.

func (*XiiRequest) TextBody

func (req *XiiRequest) TextBody(text string) *XiiRequest

TextBody sets the request body to the plain text representation of text.

func (*XiiRequest) XMLBody

func (req *XiiRequest) XMLBody(xmlData any) *XiiRequest

XMLBody sets the request body to the XML representation of xmlData.

func (*XiiRequest) YAMLBody

func (req *XiiRequest) YAMLBody(yamlData any) *XiiRequest

YAMLBody sets the request body to the YAML representation of yamlData.

type XiiResponse

type XiiResponse struct {
	Request    *XiiRequest
	StatusCode int
	Proto      string
	Headers    http.Header
	Body       []byte
}

XiiResponse represents an HTTP response with various configurable options.

func (*XiiResponse) IsClientError

func (resp *XiiResponse) IsClientError() bool

IsClientError returns true if the response status code is in the 4xx range.

func (*XiiResponse) IsError

func (resp *XiiResponse) IsError() bool

IsError returns true if the response status code is in the 4xx or 5xx range.

func (*XiiResponse) IsRedirect

func (resp *XiiResponse) IsRedirect() bool

IsRedirect returns true if the response status code is in the 3xx range.

func (*XiiResponse) IsServerError

func (resp *XiiResponse) IsServerError() bool

IsServerError returns true if the response status code is in the 5xx range.

func (*XiiResponse) IsSuccess

func (resp *XiiResponse) IsSuccess() bool

IsSuccess returns true if the response status code is in the 2xx range.

func (*XiiResponse) JSONBody

func (resp *XiiResponse) JSONBody(v any) error

JSONBody unmarshals the response body into the provided struct.

func (*XiiResponse) TextBody

func (resp *XiiResponse) TextBody() string

TextBody returns the response body as a string.

func (*XiiResponse) XMLBody

func (resp *XiiResponse) XMLBody(v any) error

XMLBody unmarshals the response body into the provided struct.

func (*XiiResponse) YAMLBody

func (resp *XiiResponse) YAMLBody(v any) error

YAMLBody unmarshals the response body into the provided struct.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL