options

package
v0.0.0-...-54d95db Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicAuth

type BasicAuth struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

BasicAuth represents HTTP Basic Authentication credentials.

type FileUpload

type FileUpload struct {
	FieldName string `json:"field_name"`
	FileName  string `json:"file_name"`
	FilePath  string `json:"file_path"`
}

FileUpload represents a file to be uploaded in a multipart form.

type RequestMetrics

type RequestMetrics struct {
	StartTime    time.Time     `json:"start_time"`
	Duration     time.Duration `json:"duration"`
	RetryCount   int           `json:"retry_count"`
	ResponseSize int64         `json:"response_size"`
}

RequestMetrics represents metrics collected during a request.

type RequestOptions

type RequestOptions struct {
	// HTTP request basics
	Method      string      `json:"method"`
	URL         string      `json:"url"`
	Headers     http.Header `json:"headers"`
	Body        string      `json:"body"`
	Form        url.Values  `json:"form"`
	QueryParams url.Values  `json:"query_params"`

	// Authentication
	BasicAuth   *BasicAuth `json:"basic_auth,omitempty"`
	BearerToken string     `json:"bearer_token,omitempty"`

	// TLS/SSL options
	CertFile  string      `json:"cert_file,omitempty"`
	KeyFile   string      `json:"key_file,omitempty"`
	CAFile    string      `json:"ca_file,omitempty"`
	Insecure  bool        `json:"insecure,omitempty"`
	TLSConfig *tls.Config `json:"-"` // Not exported to JSON

	// Proxy settings
	Proxy string `json:"proxy,omitempty"`

	// Timeout settings
	Timeout        time.Duration `json:"timeout,omitempty"`
	ConnectTimeout time.Duration `json:"connect_timeout,omitempty"`

	// Redirect behavior
	FollowRedirects bool `json:"follow_redirects,omitempty"`
	MaxRedirects    int  `json:"max_redirects,omitempty"`

	// Compression
	Compress bool `json:"compress,omitempty"`

	// HTTP version specific
	HTTP2     bool `json:"http2,omitempty"`
	HTTP2Only bool `json:"http2_only,omitempty"`

	// Cookie handling
	Cookies   []*http.Cookie `json:"cookies,omitempty"`
	CookieJar http.CookieJar `json:"-"` // Not exported to JSON

	// Custom options
	UserAgent string `json:"user_agent,omitempty"`
	Referer   string `json:"referer,omitempty"`

	// File upload
	FileUpload *FileUpload `json:"file_upload,omitempty"`

	// Retry configuration
	RetryConfig *RetryConfig `json:"retry_config,omitempty"`

	// Output options
	OutputFile string `json:"output_file,omitempty"`
	Silent     bool   `json:"silent,omitempty"`
	Verbose    bool   `json:"verbose,omitempty"`

	// Advanced options
	Context           context.Context              `json:"-"` // Not exported to JSON
	RequestID         string                       `json:"request_id,omitempty"`
	Middleware        []middlewares.MiddlewareFunc `json:"-"`
	ResponseBodyLimit int64                        `json:"response_body_limit,omitempty"`
	ResponseDecoder   ResponseDecoder              `json:"-"`
	Metrics           *RequestMetrics              `json:"metrics,omitempty"`
}

RequestOptions represents the configuration for an HTTP request in GoCurl.

func NewRequestOptions

func NewRequestOptions(url string) *RequestOptions

NewRequestOptions creates a new RequestOptions with default values aligned to cURL's defaults.

func (*RequestOptions) AddHeader

func (ro *RequestOptions) AddHeader(key, value string)

AddHeader adds a header to the request.

func (*RequestOptions) AddQueryParam

func (ro *RequestOptions) AddQueryParam(key, value string)

AddQueryParam adds a query parameter to the request URL.

func (*RequestOptions) Clone

func (ro *RequestOptions) Clone() *RequestOptions

Clone creates a deep copy of RequestOptions.

func (*RequestOptions) SetBasicAuth

func (ro *RequestOptions) SetBasicAuth(username, password string)

SetBasicAuth sets the basic authentication credentials.

func (*RequestOptions) SetHeader

func (ro *RequestOptions) SetHeader(key, value string)

SetHeader sets a header in the request, replacing any existing values.

func (*RequestOptions) SetQueryParam

func (ro *RequestOptions) SetQueryParam(key, value string)

SetQueryParam sets a query parameter in the request URL, replacing any existing values.

func (*RequestOptions) ToJSON

func (ro *RequestOptions) ToJSON() (string, error)

ToJSON marshals the RequestOptions struct to JSON format.

type RequestOptionsBuilder

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

RequestOptionsBuilder is a builder for RequestOptions.

func NewRequestOptionsBuilder

func NewRequestOptionsBuilder() *RequestOptionsBuilder

NewRequestOptionsBuilder creates a new instance of RequestOptionsBuilder.

func (*RequestOptionsBuilder) AddHeader

func (b *RequestOptionsBuilder) AddHeader(key, value string) *RequestOptionsBuilder

AddHeader adds a header to the request.

func (*RequestOptionsBuilder) AddQueryParam

func (b *RequestOptionsBuilder) AddQueryParam(key, value string) *RequestOptionsBuilder

AddQueryParam adds a query parameter to the request.

func (*RequestOptionsBuilder) Build

Build returns the configured RequestOptions instance.

func (*RequestOptionsBuilder) DELETE

DELETE creates a DELETE request with the given URL and headers.

func (*RequestOptionsBuilder) GET

GET creates a GET request with the given URL and headers.

func (*RequestOptionsBuilder) PATCH

func (b *RequestOptionsBuilder) PATCH(url string, body string, headers http.Header) *RequestOptionsBuilder

PATCH creates a PATCH request with the given URL, body, and headers.

func (*RequestOptionsBuilder) POST

func (b *RequestOptionsBuilder) POST(url string, body string, headers http.Header) *RequestOptionsBuilder

POST creates a POST request with the given URL, body, and headers.

func (*RequestOptionsBuilder) PUT

PUT creates a PUT request with the given URL, body, and headers.

func (*RequestOptionsBuilder) SetBasicAuth

func (b *RequestOptionsBuilder) SetBasicAuth(username, password string) *RequestOptionsBuilder

SetBasicAuth sets the basic authentication credentials.

func (*RequestOptionsBuilder) SetBearerToken

func (b *RequestOptionsBuilder) SetBearerToken(token string) *RequestOptionsBuilder

SetBearerToken sets the bearer token for authentication.

func (*RequestOptionsBuilder) SetBody

SetBody sets the request body.

func (*RequestOptionsBuilder) SetCAFile

func (b *RequestOptionsBuilder) SetCAFile(caFile string) *RequestOptionsBuilder

SetCAFile sets the CA file for TLS.

func (*RequestOptionsBuilder) SetCertFile

func (b *RequestOptionsBuilder) SetCertFile(certFile string) *RequestOptionsBuilder

SetCertFile sets the certificate file for TLS.

func (*RequestOptionsBuilder) SetCompress

func (b *RequestOptionsBuilder) SetCompress(compress bool) *RequestOptionsBuilder

SetCompress sets whether to enable compression.

func (*RequestOptionsBuilder) SetConnectTimeout

func (b *RequestOptionsBuilder) SetConnectTimeout(connectTimeout time.Duration) *RequestOptionsBuilder

SetConnectTimeout sets the connect timeout for the request.

func (*RequestOptionsBuilder) SetCookie

func (b *RequestOptionsBuilder) SetCookie(cookie *http.Cookie) *RequestOptionsBuilder

SetCookie adds a cookie to the request.

func (*RequestOptionsBuilder) SetFileUpload

func (b *RequestOptionsBuilder) SetFileUpload(fileUpload *FileUpload) *RequestOptionsBuilder

SetFileUpload sets the file upload configuration.

func (*RequestOptionsBuilder) SetFollowRedirects

func (b *RequestOptionsBuilder) SetFollowRedirects(follow bool) *RequestOptionsBuilder

SetFollowRedirects sets whether to follow redirects.

func (*RequestOptionsBuilder) SetForm

SetForm sets the form data for the request.

func (*RequestOptionsBuilder) SetHTTP2

func (b *RequestOptionsBuilder) SetHTTP2(http2 bool) *RequestOptionsBuilder

SetHTTP2 enables or disables HTTP/2.

func (*RequestOptionsBuilder) SetHTTP2Only

func (b *RequestOptionsBuilder) SetHTTP2Only(http2Only bool) *RequestOptionsBuilder

SetHTTP2Only enables or disables HTTP/2-only mode.

func (*RequestOptionsBuilder) SetHeaders

func (b *RequestOptionsBuilder) SetHeaders(headers http.Header) *RequestOptionsBuilder

SetHeaders sets multiple headers for the request.

func (*RequestOptionsBuilder) SetInsecure

func (b *RequestOptionsBuilder) SetInsecure(insecure bool) *RequestOptionsBuilder

SetInsecure sets whether to skip TLS verification.

func (*RequestOptionsBuilder) SetKeyFile

func (b *RequestOptionsBuilder) SetKeyFile(keyFile string) *RequestOptionsBuilder

SetKeyFile sets the key file for TLS.

func (*RequestOptionsBuilder) SetMaxRedirects

func (b *RequestOptionsBuilder) SetMaxRedirects(maxRedirects int) *RequestOptionsBuilder

SetMaxRedirects sets the maximum number of redirects to follow.

func (*RequestOptionsBuilder) SetMethod

func (b *RequestOptionsBuilder) SetMethod(method string) *RequestOptionsBuilder

SetMethod sets the HTTP method.

func (*RequestOptionsBuilder) SetOutputFile

func (b *RequestOptionsBuilder) SetOutputFile(outputFile string) *RequestOptionsBuilder

SetOutputFile sets the output file for the response.

func (*RequestOptionsBuilder) SetProxy

SetProxy sets the proxy URL.

func (*RequestOptionsBuilder) SetQueryParams

func (b *RequestOptionsBuilder) SetQueryParams(queryParams url.Values) *RequestOptionsBuilder

SetQueryParams sets the query parameters for the request.

func (*RequestOptionsBuilder) SetReferer

func (b *RequestOptionsBuilder) SetReferer(referer string) *RequestOptionsBuilder

SetReferer sets the Referer header.

func (*RequestOptionsBuilder) SetRetryConfig

func (b *RequestOptionsBuilder) SetRetryConfig(retryConfig *RetryConfig) *RequestOptionsBuilder

SetRetryConfig sets the retry configuration.

func (*RequestOptionsBuilder) SetSilent

func (b *RequestOptionsBuilder) SetSilent(silent bool) *RequestOptionsBuilder

SetSilent sets whether the request should be silent.

func (*RequestOptionsBuilder) SetTLSConfig

func (b *RequestOptionsBuilder) SetTLSConfig(tlsConfig *tls.Config) *RequestOptionsBuilder

SetTLSConfig sets the TLS configuration.

func (*RequestOptionsBuilder) SetTimeout

func (b *RequestOptionsBuilder) SetTimeout(timeout time.Duration) *RequestOptionsBuilder

SetTimeout sets the request timeout.

func (*RequestOptionsBuilder) SetURL

SetURL sets the request URL.

func (*RequestOptionsBuilder) SetUserAgent

func (b *RequestOptionsBuilder) SetUserAgent(userAgent string) *RequestOptionsBuilder

SetUserAgent sets the User-Agent header.

func (*RequestOptionsBuilder) SetVerbose

func (b *RequestOptionsBuilder) SetVerbose(verbose bool) *RequestOptionsBuilder

SetVerbose sets whether the request should be verbose.

type ResponseDecoder

type ResponseDecoder func(*http.Response) (interface{}, error)

ResponseDecoder is a function type for custom response decoding.

type RetryConfig

type RetryConfig struct {
	MaxRetries  int           `json:"max_retries"`
	RetryDelay  time.Duration `json:"retry_delay"`
	RetryOnHTTP []int         `json:"retry_on_http"`
}

RetryConfig represents the configuration for request retries.

Jump to

Keyboard shortcuts

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