http_client

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert2LogString

func Convert2LogString(object interface{}) string

func LogRpcJson

func LogRpcJson(ctx context.Context, business string, method string, params interface{}, result interface{}, err error, starTimestamp int64)

func ReadHttpResp added in v0.2.5

func ReadHttpResp(result *http.Response) (body []byte, err error)

func SendRequest

func SendRequest(ctx context.Context, client *http.Client, httpRequestParams *HttpRequestParams, requestType string, buildRequest func(*HttpRequestParams, context.Context) (*http.Request, string, error)) (result []byte, err error)

SendRequest 此方法实现的目的是作为一个通用的http调用方法,也是最核心http调用

func SendRequestOriResp

func SendRequestOriResp(ctx context.Context, client *http.Client, httpRequestParams *HttpRequestParams, requestType string, buildRequest func(*HttpRequestParams, context.Context) (*http.Request, string, error)) (result *http.Response, err error)

SendRequestOriResp 此方法实现的目的是作为一个通用的http调用方法,也是最核心http调用

Types

type HttpClient

type HttpClient struct {
	Client *http.Client
}

func Create

func Create(client *http.Client) *HttpClient

func CreateDefault

func CreateDefault() *HttpClient

func Default added in v0.2.7

func Default() *HttpClient

func (HttpClient) Delete

func (c HttpClient) Delete(ctx context.Context, httpRequestParams *HttpRequestParams) (result []byte, err error)

Delete 删除数据

func (HttpClient) Get

func (c HttpClient) Get(ctx context.Context, httpRequestParams *HttpRequestParams) (result []byte, err error)

func (HttpClient) PostFile

func (c HttpClient) PostFile(ctx context.Context, httpRequestParams *HttpRequestParams) (result []byte, err error)

func (HttpClient) PostForm

func (c HttpClient) PostForm(ctx context.Context, httpRequestParams *HttpRequestParams) (result []byte, err error)

func (HttpClient) PostJson

func (c HttpClient) PostJson(ctx context.Context, httpRequestParams *HttpRequestParams) (result []byte, err error)

func (HttpClient) PostJsonOriResp

func (c HttpClient) PostJsonOriResp(ctx context.Context, httpRequestParams *HttpRequestParams) (result *http.Response, err error)

PostJsonOriResp 此方法需要在外部设置content 超时,并进行defer cancel

type HttpRequestFileParams

type HttpRequestFileParams struct {
	FileName string
	FileData io.Reader
}

type HttpRequestParams

type HttpRequestParams struct {
	Headers    map[string]string
	Params     map[string]string
	Body       []byte
	FileParams []*HttpRequestFileParams
	Url        string
	Timeout    time.Duration
	MonitorKey string
	LogLevel   LogLevel
}

type LogLevel

type LogLevel int
const (
	LogNone   LogLevel = 0
	LogBasic  LogLevel = 1
	LogParams LogLevel = 2
	LogAll    LogLevel = 3
)

Jump to

Keyboard shortcuts

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