nhr

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FastJsonMarshal

func FastJsonMarshal(v interface{}) ([]byte, error)

FastJsonMarshal json序列化

func FastJsonUnMarshal

func FastJsonUnMarshal(data []byte, v interface{}) error

FastJsonUnMarshal json反序列化

func HttpCaller

func HttpCaller(method, url string, options ...Option) *http.Response

HttpCaller 发起请求 method: HTTP method (GET, POST, PUT,DELETE) url: 请求的url

func MontageUrl

func MontageUrl(host, apiUrl string, pathParam ...interface{}) string

MontageUrl 拼接测试的接口URL,但是不拼接查询参数,主要是为了拼接最终的url 路径参数格式为列表 ["334","456"] 当路径参数没有时,拼接的路径为 https://host/apiUrl 当路径参数参数有时,按路径顺序拼接的路径为 https://host/apiUrl/pathParam/334/456

func ResponseToMap

func ResponseToMap(responseIns *http.Response) map[string]interface{}

ResponseToMap 将响应结果转为map

func ResponseToStruct

func ResponseToStruct(responseIns *http.Response, v interface{}) error

ResponseToStruct 将字节切片类型的接口响应转接结构,通过结构体取值 response:请求的响应对象 v:结构体指针

Types

type HttpRequests

type HttpRequests struct {
	Method   string
	URL      string
	Headers  map[string]string
	Cookies  []*http.Cookie
	Timeout  time.Duration
	PostBody string
	Params   string
}

type Option

type Option func(*HttpRequests)

func WithCookies

func WithCookies(cookies []*http.Cookie) Option

WithCookies 设置cookies

func WithHeaders

func WithHeaders(headers map[string]string) Option

WithHeaders 设置请求头

func WithParams

func WithParams(params map[string]string) Option

WithParams 设置查询参数,且对url的参数进行encode

func WithPostJsonBody

func WithPostJsonBody(data map[string]interface{}) Option

WithPostJsonBody 当headers的Content-Type是application/json HTTP会将请求参数以"键-值”"的方式组织的JSON格式数据,放到请求body里面

func WithPostStringBody

func WithPostStringBody(data string) Option

WithPostStringBody 当headers的Content-Type是application/x-www-form-urlencoded HTTP会将请求参数用key1=val1&key2=val2的方式进行组织,并放到请求body里面

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout 设置请求超时时间

Jump to

Keyboard shortcuts

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