Documentation ¶
Index ¶
- Constants
- Variables
- func Get(ctx context.Context, url string, queryParams map[string][]string) *req.Response
- func GetAndInto(ctx context.Context, url string, queryParams map[string][]string, ...) error
- func GetGlobalClient() (client *req.Client)
- func NewClient(options ...ClientOption) (client *req.Client)
- func Post(ctx context.Context, url string, body interface{}) *req.Response
- func PostAndInto(ctx context.Context, url string, body interface{}, v interface{}) error
- func ReplaceGlobalClient(client *req.Client)
- func SimpleGet(ctx context.Context, url string) *req.Response
- type ClientOption
- func WithCommonErrorResult(result interface{}) ClientOption
- func WithDev() ClientOption
- func WithInsecureSkipVerify(insecureSkipVerify bool) ClientOption
- func WithLogger(logger req.Logger) ClientOption
- func WithOnAfterResponse(middleware req.ResponseMiddleware) ClientOption
- func WithRetryConditions(conditions ...req.RetryConditionFunc) ClientOption
- func WithRetryCount(retryCount int) ClientOption
- func WithRetryHooks(hooks ...req.RetryHookFunc) ClientOption
- func WithRetryInterval(getRetryInterval req.GetRetryIntervalFunc) ClientOption
- func WithTimeout(timeout time.Duration) ClientOption
Constants ¶
View Source
const ( ContentTypePlainText = "text/plain; charset=utf-8" ContentTypeJson = "application/json; charset=utf-8" ContentTypeXml = "text/xml; charset=utf-8" ContentTypeForm = "application/x-www-form-urlencoded; charset=utf-8" )
View Source
const ( // DefaultTimeout 默认超时时间 DefaultTimeout = time.Second * 30 )
Variables ¶
Functions ¶
func GetAndInto ¶ added in v3.0.911
func GetGlobalClient ¶ added in v3.0.911
func GetGlobalClient() (client *req.Client)
func NewClient ¶
func NewClient(options ...ClientOption) (client *req.Client)
NewClient
@param options 不传参的情况下, (1) 生产模式
(2) 超时时间: 30s (3) 跳过https证书验证 (4) 日志输出: os.Stdout (5) 不重试
func Post ¶
Post TODO: 待验证.
PS: 要注意 req.Response 结构体的 Err 字段.
@param body Set the request Body, accepts string、[]byte、io.Reader、map and struct.
func PostAndInto ¶ added in v3.0.911
func ReplaceGlobalClient ¶ added in v3.0.911
func ReplaceGlobalClient(client *req.Client)
Types ¶
type ClientOption ¶ added in v3.0.909
type ClientOption func(*clientOptions)
func WithCommonErrorResult ¶ added in v3.0.911
func WithCommonErrorResult(result interface{}) ClientOption
func WithDev ¶ added in v3.0.910
func WithDev() ClientOption
func WithInsecureSkipVerify ¶ added in v3.0.909
func WithInsecureSkipVerify(insecureSkipVerify bool) ClientOption
func WithLogger ¶ added in v3.0.909
func WithLogger(logger req.Logger) ClientOption
WithLogger
@param logger (1) 可以是 *logrus.Logger 实例 || *zap.SugaredLogger 实例
(2) 可以为nil(disable log, 禁用输出)
func WithOnAfterResponse ¶ added in v3.0.911
func WithOnAfterResponse(middleware req.ResponseMiddleware) ClientOption
func WithRetryConditions ¶ added in v3.0.911
func WithRetryConditions(conditions ...req.RetryConditionFunc) ClientOption
func WithRetryCount ¶ added in v3.0.911
func WithRetryCount(retryCount int) ClientOption
func WithRetryHooks ¶ added in v3.0.911
func WithRetryHooks(hooks ...req.RetryHookFunc) ClientOption
func WithRetryInterval ¶ added in v3.0.911
func WithRetryInterval(getRetryInterval req.GetRetryIntervalFunc) ClientOption
func WithTimeout ¶ added in v3.0.909
func WithTimeout(timeout time.Duration) ClientOption
Click to show internal directories.
Click to hide internal directories.