xhttp

package module
v0.0.0-...-f4e9e5f Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProtocolRegexp HTTP 协议正则
	ProtocolRegexp = "http(s)?://"
	// DefaultPortStr HTTP 默认端口
	DefaultPortStr = "80"
)

Variables

View Source
var (
	// ErrPostOptionsRequired defines the error returned when post options is nil
	ErrPostOptionsRequired = errors.New("post options required")
	// ErrPostURLRequired defines the error returned when post url is empty
	ErrPostURLRequired = errors.New("post url required")
)

Functions

func ErrFromCode

func ErrFromCode(code int) error

func Get

func Get(client *resty.Client, url string, options *GetOptions) (*resty.Response, error)

Get send get request with options

func GetURLHost

func GetURLHost(sourceURL string) (string, error)

func NewRestyClient

func NewRestyClient() *resty.Client

func NewRestyClientWithOptions

func NewRestyClientWithOptions(options ClientOptions) *resty.Client

func Post

func Post(client *resty.Client, options *PostOptions) (*resty.Response, error)

Post send post request with options

Types

type ClientOptions

type ClientOptions struct {
	RetryAttempts    int
	RetryWaitTime    time.Duration
	RetryMaxWaitTime time.Duration
}

ClientOptions ...

type GetOptions

type GetOptions struct {
	Context     context.Context
	QueryParams map[string]string
	Headers     map[string]string
}

GetOptions get options

type PostOptions

type PostOptions struct {
	Context context.Context
	Url     string
	Data    []byte
	Json    bool
	Headers map[string]string
}

PostOptions request options

Jump to

Keyboard shortcuts

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