model

package
v1.0.17 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package model 数据模型

Package model 请求数据模型package model

Index

Constants

View Source
const (
	// HTTPOk 请求成功
	HTTPOk = 200
	// RequestErr 请求错误
	RequestErr = 509
	// ParseError 解析错误
	ParseError = 510 // 解析错误
)

返回 code 码

View Source
const (
	// FormTypeHTTP http 协议
	FormTypeHTTP = "http"
	// FormTypeWebSocket webSocket 协议
	FormTypeWebSocket = "webSocket"
	// FormTypeGRPC grpc 协议
	FormTypeGRPC   = "grpc"
	FormTypeRadius = "radius"
)

支持协议

Variables

This section is empty.

Functions

func RegisterVerifyHTTP

func RegisterVerifyHTTP(verify string, verifyFunc VerifyHTTP)

RegisterVerifyHTTP 注册 http 校验函数

func RegisterVerifyWebSocket

func RegisterVerifyWebSocket(verify string, verifyFunc VerifyWebSocket)

RegisterVerifyWebSocket 注册 webSocket 校验函数

Types

type CURL

type CURL struct {
	Data map[string][]string
}

CURL curl参数解析

func ParseTheFile

func ParseTheFile(path string) (curl *CURL, err error)

ParseTheFile 从文件中解析curl

func (*CURL) GetBody

func (c *CURL) GetBody() (body string)

GetBody 获取body

func (*CURL) GetHeaders

func (c *CURL) GetHeaders() (headers map[string]string)

GetHeaders 获取请求头

func (*CURL) GetHeadersStr

func (c *CURL) GetHeadersStr() string

GetHeadersStr 获取请求头string

func (*CURL) GetMethod

func (c *CURL) GetMethod() (method string)

GetMethod 获取 请求方式

func (*CURL) GetURL

func (c *CURL) GetURL() (url string)

GetURL 获取url

func (*CURL) String

func (c *CURL) String() (url string)

String string

type Request

type Request struct {
	URL       string            // URL
	Form      string            // http/webSocket/tcp
	Method    string            // 方法 GET/POST/PUT
	Headers   map[string]string // Headers
	Body      string            // body
	Verify    string            // 验证的方法
	Timeout   time.Duration     // 请求超时时间
	Debug     bool              // 是否开启Debug模式
	MaxCon    int               // 每个连接的请求数
	HTTP2     bool              // 是否使用http2.0
	Keepalive bool              // 是否开启长连接
	Code      int               // 验证的状态码
	Redirect  bool              // 是否重定向
}

Request 请求数据

func NewRequest

func NewRequest(url string, verify string, code int, timeout time.Duration, debug bool, path string,
	reqHeaders []string, reqBody string, maxCon int, http2, keepalive, redirect bool) (request *Request, err error)

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

func (*Request) CopyHeaders added in v1.0.17

func (r *Request) CopyHeaders() map[string]string

CopyHeaders copy Headers

func (*Request) GetBody

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

GetBody 获取请求数据

func (*Request) GetDebug

func (r *Request) GetDebug() bool

GetDebug 获取 debug 参数

func (*Request) GetVerifyHTTP

func (r *Request) GetVerifyHTTP() VerifyHTTP

GetVerifyHTTP 获取数据校验方法

func (*Request) GetVerifyWebSocket

func (r *Request) GetVerifyWebSocket() VerifyWebSocket

GetVerifyWebSocket 获取数据校验方法

func (*Request) IsParameterLegal

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

IsParameterLegal 参数是否合法

func (*Request) Print

func (r *Request) Print()

Print 格式化打印

type RequestResults

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

RequestResults 请求结果

func (*RequestResults) SetID

func (r *RequestResults) SetID(chanID uint64, number uint64)

SetID 设置请求唯一ID

type Verify

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

Verify 验证器

type VerifyHTTP

type VerifyHTTP func(request *Request, response *http.Response, body []byte) (code int, isSucceed bool)

VerifyHTTP http 验证

type VerifyWebSocket

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

VerifyWebSocket webSocket 验证

Jump to

Keyboard shortcuts

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