service

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: MulanPSL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	POST    = "POST"
	GET     = "GET"
	PUT     = "PUT"
	DELETE  = "DELETE"
	OPTIONS = "OPTIONS"

	HTTP       = "HTTP"
	HTTPS      = "HTTPS"
	TCP        = "TCP"
	WEBSOCKET  = "WEBSOCKET"
	WEBSOCKETS = "WEBSOCKETS"

	ErrRequest = -1 // 请求失败
	ErrCheck   = -2 // 校验失败
)

Variables

This section is empty.

Functions

func Dispose

func Dispose(ctx context.Context, wg *sync.WaitGroup, ch chan<- *Response, concurrencyMap *CMap, chanID, singleRequestNum int, registry *VariableRegistry, requests ...Request)

Dispose 线程处理函数

Types

type CMap added in v0.1.0

type CMap struct {
	TN int
	CN int
	// contains filtered or unexported fields
}

func (*CMap) CNAdd added in v0.1.0

func (c *CMap) CNAdd(num int)

func (*CMap) CNDel added in v0.1.0

func (c *CMap) CNDel(num int)

CNDel 从CN计数器中减去一个数值,确保结果不小于0

func (*CMap) CNGet added in v0.1.0

func (c *CMap) CNGet() int

CNGet 获取CN计数器的当前值

func (*CMap) TNAdd added in v0.1.0

func (c *CMap) TNAdd(num int)

TNAdd 向指定的chanId添加num值,如果chanId不存在则创建它

func (*CMap) TNDel added in v0.1.0

func (c *CMap) TNDel(num int)

func (*CMap) TNGet added in v0.1.0

func (c *CMap) TNGet() int

TNGet 获取TN值

type FileProvider added in v0.1.0

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

FileProvider 文件语料提供器,支持 TXT/CSV/XLSX 格式,线程安全轮询读取

func NewFileProvider added in v0.1.0

func NewFileProvider(path, sheet, column string) (*FileProvider, error)

NewFileProvider 根据文件扩展名创建对应的 FileProvider

func (*FileProvider) Next added in v0.1.0

func (f *FileProvider) Next() string

Next 返回当前行并将游标前移,到达末尾后回绕到 0,线程安全

type HttpRequest added in v0.1.0

type HttpRequest struct {
	URL       string            `json:"url,omitempty"`       // 请求地址
	Method    string            `json:"method,omitempty"`    // 请求方法 GET/ POST/ PUT/ DELETE/ OPTIONS
	Headers   map[string]string `json:"headers,omitempty"`   // 请求头 Headers
	Body      string            `json:"body,omitempty"`      // 请求体 body
	Verify    []verify          `json:"verify,omitempty"`    // 验证的方法
	Timeout   time.Duration     `json:"timeout,omitempty"`   // 请求超时时间 s
	Debug     bool              `json:"debug,omitempty"`     // 是否开启Debug模式
	MaxCon    int               `json:"maxCon,omitempty"`    // 每个连接的请求数
	SSL       bool              `json:"SSL,omitempty"`       // 证书验证
	Keepalive bool              `json:"keepalive,omitempty"` // 是否开启长连接
	Redirect  bool              `json:"redirect,omitempty"`  // 是否重定向
	Streaming bool              `json:"streaming,omitempty"` // 是否为流式响应(SSE)
	// contains filtered or unexported fields
}

HttpRequest 请求对象

func (*HttpRequest) AddCookies added in v0.1.0

func (h *HttpRequest) AddCookies(cookies ...*http.Cookie)

func (*HttpRequest) InitTemplates added in v0.1.0

func (h *HttpRequest) InitTemplates(needsBody bool) error

InitTemplates 预解析 URL、Headers、Body 中的模板变量

func (*HttpRequest) Send added in v0.1.0

func (h *HttpRequest) Send() *Response

Send 发送当前的 HTTP 请求并返回一个 Response 对象。

func (*HttpRequest) SetRegistry added in v0.1.0

func (h *HttpRequest) SetRegistry(registry *VariableRegistry)

SetRegistry 设置变量注册表

func (*HttpRequest) String added in v0.1.0

func (h *HttpRequest) String() string

func (*HttpRequest) Validate added in v0.1.0

func (h *HttpRequest) Validate() error

type Request added in v0.1.0

type Request interface {
	String() string                         // 格式化打印 请求信息
	Send() *Response                        // 发送请求
	AddCookies(cookies ...*http.Cookie)     // 设置cookie
	Validate() error                        // 校验请求配置
	InitTemplates(needsBody bool) error     // 初始化模板
	SetRegistry(registry *VariableRegistry) // 设置变量注册表
}

Request 请求对象接口

func NewHttpClient added in v0.1.0

func NewHttpClient(jsonFile string) ([]Request, error)

NewHttpClient 从指定 JSON 文件中读取请求配置并返回 Request 接口切片

type Response added in v0.1.0

type Response struct {
	ChanID         int            // 消息ID
	Time           time.Duration  // 响应耗时 ms
	CheckStatus    bool           // 是否请求成功
	StatusCode     int            // 响应状态码
	ReceivedBytes  int64          // 接收字节数
	Cookies        []*http.Cookie // 响应cookie
	IsStreaming    bool           // 是否为流式响应
	FirstEventTime time.Duration  // 首个完整事件到达时间(TTFT)
	Body           []byte         // 响应体(仅在需要提取时保存)
}

func (*Response) Update added in v0.1.0

func (r *Response) Update(resp *Response) error

type Segment added in v0.1.0

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

Segment 表示模板中的一个片段,可以是静态文本或变量引用

type Template added in v0.1.0

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

Template 表示解析后的模板,由多个片段组成

func ParseTemplate added in v0.1.0

func ParseTemplate(s string) (*Template, error)

ParseTemplate 将模板字符串解析为 Template 对象 支持 {{varName}} 语法,混合静态文本和变量引用

func (*Template) Execute added in v0.1.0

func (t *Template) Execute(registry *VariableRegistry) string

Execute 使用变量注册表执行模板,返回替换后的字符串

type VariableRegistry added in v0.1.0

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

VariableRegistry 变量注册表,管理所有变量生成器

func NewVariableRegistry added in v0.1.0

func NewVariableRegistry(baseDir string) *VariableRegistry

NewVariableRegistry 创建新的变量注册表

func (*VariableRegistry) Resolve added in v0.1.0

func (r *VariableRegistry) Resolve(name string) string

Resolve 解析变量名,返回对应的值 支持的变量类型:

  • "uuid" → UUID v4 字符串
  • "counter" → 原子递增计数器(从 1 开始)
  • "timestamp" → 当前 Unix 毫秒时间戳
  • "random:min,max" → [min, max] 范围内的随机整数
  • "resp:jsonpath" → 从响应值映射中查找

func (*VariableRegistry) SetRespValue added in v0.1.0

func (r *VariableRegistry) SetRespValue(path, value string)

SetRespValue 设置响应值,供 resp: 变量类型使用

Jump to

Keyboard shortcuts

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