pkg

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HttpOk         = 200 // 请求成功
	RequestTimeout = 506 // 请求超时
	RequestErr     = 509 // 请求错误
	ParseError     = 510 // 解析错误

	FormTypeHttp      = "http"
	FormTypeWebSocket = "webSocket"
	DefaultMethod     = "GET"
	DefaultVerifyCode = "statusCode"
	DefaultTimeOut    = 30 * time.Second
)

Variables

View Source
var (
	Concurrency int      // Concurrency is 并发请求数
	Number      uint64   // Number is 单个协程的请求总数
	Debug       bool     // Debug is 是否开其调试模式
	Path        string   // Path is curl 文件路径
	VerifyStr   string   // VerifyStr is 验证方法
	RequestUrl  string   // RequestUrl is 压力测试的Url
	Header      []string // Header is 自定义头信息传递给服务器
	Body        string   // Body is HTTP POST data 上传的数据
	Compressed  bool     // Compressed is curl zip algorithm
)

Functions

func GetZipData added in v1.1.1

func GetZipData(response *http.Response) (body []byte, err error)

处理gzip压缩

func Http

func Http(chanId int, ch chan<- *RequestResults, totalNumber uint64, wg *sync.WaitGroup, request *Request)

Http is http go link

func HttpJson added in v1.0.3

func HttpJson(request *Request, response *http.Response) (code int, isSucceed bool)

HttpJson is 通过返回的Body 判断 返回示例: {"code":200,"msg":"Success","data":{}} code 默认将http code作为返回码,http code 为200时 取body中的返回code

func HttpMulti added in v1.1.1

func HttpMulti(chanId int, ch chan<- *RequestResults, totalNumber uint64, wg *sync.WaitGroup, request *Request)

HttpMulti is 处理行数大于100的逻辑。

func HttpRequest added in v1.0.3

func HttpRequest(method, url string, body io.Reader, headers utils.ConcurrentMap, timeout time.Duration) (resp *http.Response, requestTime uint64, err error)

HttpRequest is HTTP 请求 method 方法 GET POST url 请求的url body 请求的body headers 请求头信息 timeout 请求超时时间

func HttpStatusCode added in v1.0.3

func HttpStatusCode(request *Request, response *http.Response) (code int, isSucceed bool)

HttpStatusCode is 通过Http状态码判断是否请求成功

func MallVersionJson added in v1.0.3

func MallVersionJson(request *Request, response *http.Response) (code int, isSucceed bool)

MallVersionJson 通过返回的Body 判断

func ReceivingResults

func ReceivingResults(concurrent int, ch <-chan *RequestResults, wg *sync.WaitGroup)

ReceivingResults is 接收结果并处理 统计的时间都是纳秒,显示的时间 都是毫秒 concurrent 并发数

func RegisterVerifyHttp

func RegisterVerifyHttp(verify string, verifyFunc VerifyHttp)

RegisterVerifyHttp is 注册http校验函数

func RegisterVerifyWebSocket

func RegisterVerifyWebSocket(verify string, verifyFunc VerifyWebSocket)

RegisterVerifyWebSocket is 注册webSocket校验函数

func WebSocket

func WebSocket(chanId int, ch chan<- *RequestResults, totalNumber uint64, wg *sync.WaitGroup, request *Request, ws *WebSocketC)

WebSocket is web socket go link

func WebSocketJson added in v1.0.3

func WebSocketJson(request *Request, seq string, msg []byte) (code int, isSucceed bool)

WebSocketJson is 通过返回的Body 判断 返回示例: {"seq":"1566276523281-585638","cmd":"heartbeat","response":{"code":200,"codeMsg":"Success","data":null}} code 取body中的返回code

Types

type MallVersion added in v1.0.3

type MallVersion struct {
	Status     int    `json:"status"`
	Result     string `json:"result"`
	TraceId    string `json:"traceId"`
	DevMessage string `json:"devMessage"`
	Message    string `json:"message"`
	Url        string `json:"url"`
}

MallVersion is for mall.youpenglai.com/apis/version

type Req

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

Req is weights for request

type ReqListWeigh

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

ReqListWeigh 接口加权压测

type Request

type Request struct {
	Url     string              // Url
	Form    string              // http/webSocket/tcp
	Method  string              // 方法 GET/POST/PUT
	Headers utils.ConcurrentMap // Headers
	Body    string              // body
	Verify  string              // 验证的方法
	Timeout time.Duration       // 请求超时时间
	Debug   bool                // 是否开启Debug模式

}

Request is a form for http request 请求结果

func GetRequestListFromFile

func GetRequestListFromFile(path string) (clients []*Request)

func NewDefaultRequest

func NewDefaultRequest() *Request

NewDefaultRequest is a default request

func NewRequest

func NewRequest(url string, verify string, timeout time.Duration, debug bool, reqHeaders []string, reqBody string) (request *Request, err error)

NewRequest is get Request form url 压测的url verify 验证方法 在server/verify中 http 支持:statusCode、json webSocket支持:json timeout 请求超时时间 debug 是否开启debug path curl文件路径 http接口压测,自定义参数设置

func (*Request) GetBody

func (r *Request) GetBody() (body io.Reader)

GetBody return io.Reader from request

func (*Request) GetDebug

func (r *Request) GetDebug() bool

GetDebug is use Debug mode

func (*Request) GetVerifyHttp

func (r *Request) GetVerifyHttp() VerifyHttp

GetVerifyHttp is 获取数据校验方法

func (*Request) GetVerifyWebSocket

func (r *Request) GetVerifyWebSocket() VerifyWebSocket

GetVerifyWebSocket is 获取数据校验方法

func (*Request) IsParameterLegal

func (r *Request) IsParameterLegal() (err error)

IsParameterLegal is verify param is legal

func (*Request) Print

func (r *Request) Print()

Print is 打印参数

type RequestResults

type RequestResults struct {
	Id        string // 消息Id
	ChanId    int    // 消息Id
	Time      uint64 // 请求时间 纳秒
	IsSucceed bool   // 是否请求成功
	ErrCode   int    // 错误码
}

RequestResults is 请求结果

func (*RequestResults) SetId

func (r *RequestResults) SetId(chanId int, number uint64)

SetId is set chanId & id to request results

type ResponseJson added in v1.0.3

type ResponseJson struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

返回数据结构体

type Verify

type Verify interface {
	GetCode() int    // 有一个方法,返回code为200为成功
	GetResult() bool // 返回是否成功
}

Verify is interface for 验证器

type VerifyHttp

type VerifyHttp func(request *Request, response *http.Response) (code int, isSucceed bool)

VerifyHttp is verify for http 验证方法

type VerifyWebSocket

type VerifyWebSocket func(request *Request, seq string, msg []byte) (code int, isSucceed bool)

VerifyWebSocket is verify for websocket

type WebSocketC added in v1.0.3

type WebSocketC struct {
	UrlLink string
	Url     *url.URL
	IsSsl   bool
	// contains filtered or unexported fields
}

WebSocketC is client for websocket

func NewWebSocket added in v1.0.3

func NewWebSocket(urlLink string) (ws *WebSocketC)

NewWebSocket is get WebSocketC

func (*WebSocketC) Close added in v1.0.3

func (w *WebSocketC) Close() (err error)

Close is 关闭

func (*WebSocketC) GetConn added in v1.0.3

func (w *WebSocketC) GetConn() (err error)

GetConn is get connection

func (*WebSocketC) Read added in v1.0.3

func (w *WebSocketC) Read() (msg []byte, err error)

Read is 接收数据

func (*WebSocketC) Write added in v1.0.3

func (w *WebSocketC) Write(body []byte) (err error)

Write is 发送数据

type WebSocketResponseJson added in v1.0.3

type WebSocketResponseJson struct {
	Seq      string `json:"seq"`
	Cmd      string `json:"cmd"`
	Response struct {
		Code    int         `json:"code"`
		CodeMsg string      `json:"codeMsg"`
		Data    interface{} `json:"data"`
	} `json:"response"`
}

WebSocketResponseJson is 返回数据结构体

Jump to

Keyboard shortcuts

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