httpc

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserAgent      = "HiBug Client"
	TimeoutSeconds = 60
	MaxRetryCount  = 3
)

Variables

This section is empty.

Functions

func Delete

func Delete(url string, rfs ...RequestFunc) (*resty.Response, error)

func Download

func Download(url, path string, rfs ...RequestFunc) error

Download retrieves content from the given url and write it to path.

func Fetch added in v0.1.13

func Fetch(c *FetchConf) (contents []byte, err error)

func FormFetch added in v0.1.13

func FormFetch(c *FetchConf) (contents []byte, err error)

FormFetch 表单提交

func Get

func Get(url string, rfs ...RequestFunc) (*resty.Response, error)
func Head(url string, rfs ...RequestFunc) (*resty.Response, error)

func JwtUnauthorizedResult

func JwtUnauthorizedResult(w http.ResponseWriter, r *http.Request, err error)

func NewErrorFromRestyResponse

func NewErrorFromRestyResponse(res *resty.Response) *errorx.Error

func Options

func Options(url string, rfs ...RequestFunc) (*resty.Response, error)

func Patch

func Patch(url string, rfs ...RequestFunc) (*resty.Response, error)

func Post

func Post(url string, rfs ...RequestFunc) (*resty.Response, error)

func Put

func Put(url string, rfs ...RequestFunc) (*resty.Response, error)

func RespError

func RespError(w http.ResponseWriter, r *http.Request, err error)

func RespSuccess

func RespSuccess(ctx context.Context, w http.ResponseWriter, resp interface{})

func Stringify added in v0.1.13

func Stringify(v interface{}) string

Types

type Client

type Client struct {
	*resty.Client

	Host    string // Host is the fully qualified domain name of the system, or an IP Address. Port and protocol are required if necessary.
	BaseURI string // BaseURI is the base uri for every request, starting with a slash, for example: /api/v1
	//IgnoreCodes sets.Int // IgnoreCodes ignores some code to be returned as an error.
	IgnoreCodes sets.Set[int]
}

func New

func New(cfs ...ClientFunc) *Client

func (*Client) Delete

func (c *Client) Delete(url string, rfs ...RequestFunc) (*resty.Response, error)

func (*Client) Get

func (c *Client) Get(url string, rfs ...RequestFunc) (*resty.Response, error)

func (*Client) Head

func (c *Client) Head(url string, rfs ...RequestFunc) (*resty.Response, error)

func (*Client) Options

func (c *Client) Options(url string, rfs ...RequestFunc) (*resty.Response, error)

func (*Client) Patch

func (c *Client) Patch(url string, rfs ...RequestFunc) (*resty.Response, error)

func (*Client) Post

func (c *Client) Post(url string, rfs ...RequestFunc) (*resty.Response, error)

func (*Client) Put

func (c *Client) Put(url string, rfs ...RequestFunc) (*resty.Response, error)

func (*Client) Request

func (c *Client) Request(method, url string, rfs ...RequestFunc) (*resty.Response, error)

type ClientFunc

type ClientFunc func(*Client)

func SetAuthScheme

func SetAuthScheme(scheme string) ClientFunc

func SetAuthToken

func SetAuthToken(token string) ClientFunc

func SetBaseURI

func SetBaseURI(uri string) ClientFunc

func SetBasicAuth

func SetBasicAuth(username, password string) ClientFunc

func SetClientHeader

func SetClientHeader(header, value string) ClientFunc

func SetHostURL

func SetHostURL(url string) ClientFunc

func SetIgnoreCodes

func SetIgnoreCodes(codes ...int) ClientFunc

func SetProxy

func SetProxy(proxyURL string) ClientFunc

func SetRetryCount

func SetRetryCount(count int) ClientFunc

func SetRetryWaitTime

func SetRetryWaitTime(waitTime time.Duration) ClientFunc

func SetTLSClientConfig

func SetTLSClientConfig(config *tls.Config) ClientFunc

func UnsetTimeout

func UnsetTimeout() ClientFunc

type FetchConf added in v0.1.13

type FetchConf struct {
	Method      string
	URL         string
	Data        any
	Headers     map[string]string
	AccessToken string
}

type RequestFunc

type RequestFunc func(request *resty.Request)

func ForceContentType

func ForceContentType(contentType string) RequestFunc

func SetBody

func SetBody(body interface{}) RequestFunc

func SetFileReader added in v0.2.2

func SetFileReader(param, fileName string, reader io.Reader) RequestFunc

func SetFormData

func SetFormData(data map[string]string) RequestFunc

func SetHeader

func SetHeader(header, value string) RequestFunc

func SetHeaders

func SetHeaders(headers map[string]string) RequestFunc

func SetHeadersFromHTTPHeader

func SetHeadersFromHTTPHeader(header http.Header) RequestFunc

func SetPathParam added in v0.2.1

func SetPathParam(param, value string) RequestFunc

func SetPathParams added in v0.2.1

func SetPathParams(params map[string]string) RequestFunc

func SetQueryParam

func SetQueryParam(param, value string) RequestFunc

func SetQueryParams

func SetQueryParams(params map[string]string) RequestFunc

func SetQueryParamsFromValues

func SetQueryParamsFromValues(params url.Values) RequestFunc

func SetResult

func SetResult(res interface{}) RequestFunc

type Response

type Response struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data any    `json:"data"`
}

Jump to

Keyboard shortcuts

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