sdreq

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package sdreq req库扩展

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogger req.Logger = logger{}

Functions

func GetForBytes

func GetForBytes(ctx context.Context, client *req.Client, url string, opts ...RequestOption) (int, []byte, error)

func GetForJson

func GetForJson[R any](ctx context.Context, client *req.Client, url string, opts ...RequestOption) (int, R, error)

func GetForResponse

func GetForResponse(ctx context.Context, client *req.Client, url string, opts ...RequestOption) (*req.Response, error)

func GetForText

func GetForText(ctx context.Context, client *req.Client, url string, opts ...RequestOption) (int, string, error)

func New

func New(opts *Options) *req.Client

func PostForBytes

func PostForBytes(ctx context.Context, client *req.Client, url string, body any, opts ...RequestOption) (int, []byte, error)

func PostForJson

func PostForJson[R any](ctx context.Context, client *req.Client, url string, body any, opts ...RequestOption) (int, R, error)

func PostForResponse

func PostForResponse(ctx context.Context, client *req.Client, url string, body any, opts ...RequestOption) (*req.Response, error)

func PostForText

func PostForText(ctx context.Context, client *req.Client, url string, body any, opts ...RequestOption) (int, string, error)

func ToQueryParam

func ToQueryParam(v any) string

func ToQueryParams

func ToQueryParams(params map[string]any) map[string]string

Types

type Options

type Options struct {
	// common
	BaseUrl      string
	UserAgent    string
	Headers      map[string]string
	QueryParams  map[string]string
	PathParams   map[string]string
	AuthUsername string
	AuthPassword string
	Cookies      []*http.Cookie

	// cert
	Certs        []tls.Certificate
	CertFilename string
	KeyFilename  string

	// log/dump
	Log      bool
	DebugLog bool
	DumpAll  bool

	// timeout / retry
	TimeoutMS       int64 // 超时时间,单位毫秒
	RetryIntervalMS int64
	RetryCount      int
}

type RequestOption

type RequestOption func(*req.Request) *req.Request

func EnableDump

func EnableDump() RequestOption
func Header(k, v string) RequestOption

func Headers

func Headers(headers map[string]string) RequestOption

func QueryParam

func QueryParam(k string, v any) RequestOption

func QueryParams

func QueryParams(params map[string]any) RequestOption

Jump to

Keyboard shortcuts

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