client

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommonResponse

func CommonResponse[RES any]() client.ResponseBodyCheck

func CommonResponse2

func CommonResponse2[RES any]() client.ResponseBodyCheck

func CommonResponse3

func CommonResponse3[RES any]() client.ResponseBodyCheck

func Get

func Get[RES any](url string, param any) (*RES, error)

func GetSubData

func GetSubData[RES ResponseInterface[T], T any](url string) (T, error)

func GetWithOption

func GetWithOption[RES ResponseInterface[T], T any](url string, options ...client.Option) (T, error)

Types

type Client added in v1.14.0

type Client[RES any] client.Client

Client ...

func New added in v1.7.8

func New[RES any]() *Client[RES]

func NewFromClient added in v1.14.0

func NewFromClient[RES any](req *client.Client) *Client[RES]

func (*Client[RES]) AddHeader added in v1.14.0

func (r *Client[RES]) AddHeader(k, v string) *Client[RES]

func (*Client[RES]) BasicAuth added in v1.14.0

func (r *Client[RES]) BasicAuth(authUser, authPass string)

func (*Client[RES]) ContentType added in v1.14.0

func (r *Client[RES]) ContentType(contentType client.ContentType) *Client[RES]

func (*Client[RES]) Context added in v1.14.0

func (r *Client[RES]) Context(ctx context.Context) *Client[RES]

func (*Client[RES]) DisableLog added in v1.14.0

func (r *Client[RES]) DisableLog() *Client[RES]

func (*Client[RES]) Do added in v1.14.0

func (r *Client[RES]) Do(method, url string, req any) (*RES, error)

Do create a HTTP request

func (*Client[RES]) Get added in v1.14.0

func (r *Client[RES]) Get(url string, param any) (*RES, error)

func (*Client[RES]) Header added in v1.14.0

func (r *Client[RES]) Header(header http.Header) *Client[RES]

func (*Client[RES]) HttpClient added in v1.14.0

func (r *Client[RES]) HttpClient(c *http.Client) *Client[RES]

func (*Client[RES]) LogLevel added in v1.14.0

func (r *Client[RES]) LogLevel(lvl client.LogLevel) *Client[RES]

func (*Client[RES]) Logger added in v1.14.0

func (r *Client[RES]) Logger(logger client.AccessLog) *Client[RES]

func (*Client[RES]) Origin added in v1.14.0

func (r *Client[RES]) Origin() *client.Client

func (*Client[RES]) ParseTag added in v1.14.0

func (r *Client[RES]) ParseTag(tag string) *Client[RES]

func (*Client[RES]) Post added in v1.14.0

func (r *Client[RES]) Post(url string, param any) (*RES, error)

func (*Client[RES]) Proxy added in v1.14.0

func (r *Client[RES]) Proxy(url string) *Client[RES]

func (*Client[RES]) ResponseHandler added in v1.14.0

func (r *Client[RES]) ResponseHandler(handler func(response *http.Response) (retry bool, data []byte, err error)) *Client[RES]

handler 返回值:是否重试,返回数据,错误

func (*Client[RES]) RetryHandler added in v1.14.0

func (r *Client[RES]) RetryHandler(handle func(*client.Client)) *Client[RES]

func (*Client[RES]) RetryTimes added in v1.14.0

func (r *Client[RES]) RetryTimes(retryTimes int) *Client[RES]

func (*Client[RES]) RetryTimesWithInterval added in v1.14.0

func (r *Client[RES]) RetryTimesWithInterval(retryTimes int, retryInterval time.Duration) *Client[RES]

func (*Client[RES]) SetRequest added in v1.14.0

func (r *Client[RES]) SetRequest(handle func(*client.Client)) *Client[RES]

func (*Client[RES]) Timeout added in v1.14.0

func (r *Client[RES]) Timeout(timeout time.Duration) *Client[RES]

type Option added in v1.7.8

type Option[RES any] func(req *Client[RES])

type Request

type Request[RES any] client.Request

func NewGet added in v1.12.11

func NewGet[RES any](url string) *Request[RES]

func NewRequest

func NewRequest[RES any](method, url string) *Request[RES]

func (*Request[RES]) Delete added in v1.14.0

func (req *Request[RES]) Delete(param any) error

func (*Request[RES]) Do

func (req *Request[RES]) Do(param any) error

func (*Request[RES]) Get added in v1.7.8

func (req *Request[RES]) Get(param any) error

func (*Request[RES]) Post added in v1.7.8

func (req *Request[RES]) Post(param any) error

func (*Request[RES]) Put added in v1.14.0

func (req *Request[RES]) Put(param any) error

type ResponseBody

type ResponseBody[RES any] httpi.ResData[RES]

func (*ResponseBody[RES]) CheckError

func (res *ResponseBody[RES]) CheckError() error

func (*ResponseBody[RES]) GetData

func (res *ResponseBody[RES]) GetData() *RES

type ResponseBody2

type ResponseBody2[RES any] struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data RES    `json:"data"`
}

func (*ResponseBody2[RES]) CheckError

func (res *ResponseBody2[RES]) CheckError() error

func (*ResponseBody2[RES]) GetData

func (res *ResponseBody2[RES]) GetData() *RES

type ResponseBody3

type ResponseBody3[RES any] struct {
	Status  int    `json:"status"`
	Data    RES    `json:"data"`
	Message string `json:"message"`
}

func (*ResponseBody3[RES]) CheckError

func (res *ResponseBody3[RES]) CheckError() error

type ResponseInterface

type ResponseInterface[T any] interface {
	client.ResponseBodyCheck
	GetData() T
}

type SubDataRequest

type SubDataRequest[RES ResponseInterface[T], T any] Request[RES]

一个语法糖,一般不用

func NewSubDataRequestParams added in v1.7.8

func NewSubDataRequestParams[RES ResponseInterface[T], T any](req *client.Request) *SubDataRequest[RES, T]

func (*SubDataRequest[RES, T]) Do

func (r *SubDataRequest[RES, T]) Do(param any) (T, error)

Do create a HTTP request

func (*SubDataRequest[RES, T]) Get added in v1.7.8

func (req *SubDataRequest[RES, T]) Get(param any) (T, error)

func (*SubDataRequest[RES, T]) Origin

func (req *SubDataRequest[RES, T]) Origin() *client.Request

Jump to

Keyboard shortcuts

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