hkit

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

README

hkit

一个HTTP的请求包,主要是复用连接.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(iOpt *Option)

Init 初始化

func Release

func Release()

Release 释放

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine 用于描述一个httpclient

func Get

func Get() *Engine

Get 获取单例

func (*Engine) BaseHeader

func (E *Engine) BaseHeader(iBaseHeader []HTTPOption)

BaseHeader 设置baseheader

func (*Engine) DO

func (E *Engine) DO(
	iCtx context.Context,
	iReq *Request,
) (*Response, error)

DO 用于发起一个自定义请求的接口

func (*Engine) GET

func (E *Engine) GET(
	iCtx context.Context,
	iURL string,
	iParams map[string]string,
	iHeader ...HTTPOption,
) (
	[]byte,
	error,
)

GET 用于发送get请求

func (*Engine) JSON

func (E *Engine) JSON(
	iCtx context.Context,
	iURL string,
	iObject interface{},
	iHeader ...HTTPOption,
) (
	[]byte,
	error,
)

JSON JSON类消息

func (*Engine) POST

func (E *Engine) POST(
	iCtx context.Context,
	iURL string,
	iArgs map[string]string,
	iHeader ...HTTPOption,
) (
	[]byte,
	error,
)

POST HTTP POST类消息

type HTTPOption

type HTTPOption func(req *http.Request)

HTTPOption 定义一个http的选项

func SetHeader

func SetHeader(key string, value string) HTTPOption

SetHeader 设置头部

type Option

type Option struct {
	MaxIdleConns        int  `yaml:"max_idle_conns"`
	IdleConnTimeout     int  `yaml:"idle_conn_timeout"`
	MaxIdleConnsPerHost int  `yaml:"max_idle_conn_per_host"`
	DisableCompression  bool `yaml:"disable_compress"`
	SkipTLSVerify       bool `yaml:"skip_tls_verify"`
	RetryInterval       int  `yaml:"retry_interval"`

	RetryCount  int    `yaml:"retry_count"`
	EnableProxy bool   `yaml:"enable_proxy"`
	ProxyAddr   string `yaml:"proxy_addr"`
	EnableHTTP2 bool   `yaml:"enable_http2"`
	// contains filtered or unexported fields
}

Option 用于描述一个选项配置

type Request

type Request struct {
	Method string
	URL    string
	Body   []byte
	Header []HTTPOption
}

Request 用于描述一个请求

type Response

type Response struct {
	Status int
	Header http.Header
	Body   []byte
}

Response 用于描述一个响应

type RetryConfig

type RetryConfig struct {
	// contains filtered or unexported fields
}

RetryConfig 重试配置

Jump to

Keyboard shortcuts

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