httpclient

package
v0.0.0-...-0132757 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RTClient

type RTClient struct {
	Client *http.Client
	// contains filtered or unexported fields
}

func NewHttpClient

func NewHttpClient(client *http.Client, timeOut int, serverHost string, maxRetry int) (*RTClient, error)

func (*RTClient) Delete

func (c *RTClient) Delete() *Request

func (*RTClient) Get

func (c *RTClient) Get() *Request

func (*RTClient) Patch

func (c *RTClient) Patch() *Request

func (*RTClient) Post

func (c *RTClient) Post() *Request

func (*RTClient) Put

func (c *RTClient) Put() *Request

func (*RTClient) Verb

func (c *RTClient) Verb(verb string) *Request

type Request

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

func (*Request) Body

func (r *Request) Body(obj interface{}) *Request

Body makes the request use obj as the body. Optional. If obj is a string, try to read a file of that name. If obj is a []byte, send it directly. If obj is an io.Reader, use it directly. If obj is a nil, return Request directly. Otherwise, set an error.

func (*Request) Do

func (r *Request) Do(ctx context.Context) Result

Do formats and executes the request. Returns a Result object

func (*Request) MaxRetries

func (r *Request) MaxRetries(maxRetries int) *Request

func (*Request) Prefix

func (r *Request) Prefix(prefixPath ...string) *Request

Prefix set api url prefix

func (*Request) RequestURL

func (r *Request) RequestURL(uri string) *Request

RequestURL overwrites existing path and parameters with the value of the provided server relative for example: uri= http://www.example.com:8080/api overwrites info: r.path=/api;r.shceme=http;r.host=www.example.com:8080

func (*Request) SetHeader

func (r *Request) SetHeader(key string, values ...string) *Request

func (*Request) SetParams

func (r *Request) SetParams(paramName, value string) *Request

SetParams creates a query parameter with the given string value.

func (*Request) SetPath

func (r *Request) SetPath(suffixPath ...string) *Request

SetPath set api url sub path

func (*Request) Stream

func (r *Request) Stream(ctx context.Context) (io.ReadCloser, error)

Stream formats and executes the request, and offers streaming of the response. Returns io.ReadCloser which could be used for streaming of the response, or an error

func (*Request) Timeout

func (r *Request) Timeout(d time.Duration) *Request

func (*Request) URL

func (r *Request) URL() *url.URL

URL return current request url info

func (*Request) Verb

func (r *Request) Verb(verb string) *Request

type Result

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

func (Result) Error

func (r Result) Error() error

Error return executing the request error info

func (Result) Into

func (r Result) Into(obj any) error

Into Unmarshal response data into struct obj, an error will be returned if the Result object has an error or a deserialization error

func (Result) Raw

func (r Result) Raw() ([]byte, error)

Raw return response raw data and error

func (Result) StatusCode

func (r Result) StatusCode() int

StatusCode return http response status code

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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