http_client

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert2LogString added in v0.1.5

func Convert2LogString(object interface{}) string

func Get

func Get(ctx context.Context, params *HttpRequestParams) ([]byte, error)

func LogRpcJson added in v0.1.5

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

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 GetClient

func GetClient() 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) LoadType

func (c HttpClient) LoadType() string

func (HttpClient) PostFile

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

PostFile 如果想传递其他参数,则通过params传递

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

func (HttpClient) Stop

func (c HttpClient) Stop() error

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

	Url        string
	Timeout    time.Duration
	MonitorKey string
	LogLevel   LogLevel
	// contains filtered or unexported fields
}

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