http

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GET = "GET"
	//HEAD   = "HEAD"
	POST   = "POST"
	PUT    = "PUT"
	DELETE = "DELETE"
	//CONNECT = "CONNECT"
	PATCH = "PATCH"
)
View Source
const (
	TIMEOUT = 10 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Timeout   time.Duration
	RoundTrip bool

	Transport *http.Transport
	Client    *http.Client
}

func InitClient

func InitClient(timeout time.Duration, roundTrip bool) *Client

func (*Client) Send

func (c *Client) Send(req *Request, result chan<- *Response)

func (*Client) ToggleRoundTrip

func (c *Client) ToggleRoundTrip()

type FastClient

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

func NewFastClient

func NewFastClient(timeout time.Duration, s *JobConfig) *FastClient

func (*FastClient) Do

func (f *FastClient) Do(
	fr *FastRequest,
	req *fasthttp.Request,
	res *fasthttp.Response,
) (status int, contentLen int64, err error)

type FastRequest

type FastRequest struct {
	Method  []byte
	URL     []byte
	Headers []HeaderEntry
	Body    []byte
}

type HeaderEntry

type HeaderEntry struct {
	Key   []byte
	Value []byte
}

type JobConfig

type JobConfig struct {
	// Request config
	Request     *Request // base request to send
	FastRequest *FastRequest

	// Load parameters
	Concurrency   int           // number of concurrent requests
	TotalRequests int           // total requests to send
	RateLimit     int           // max requests per second
	Timeout       time.Duration // time per request
	QPS           float64       // rate limit for queries per second
	// contains filtered or unexported fields
}

func (*JobConfig) Run

func (s *JobConfig) Run(updates chan<- *LoadTestStats)

Run makes all the requests and streams results

type LoadTestCompleteMsg

type LoadTestCompleteMsg struct {
	Stats    *LoadTestStats
	Duration time.Duration
}

type LoadTestErrorMsg

type LoadTestErrorMsg struct {
	Error error
}

type LoadTestStartMsg

type LoadTestStartMsg struct {
	Config *JobConfig
}

type LoadTestStats

type LoadTestStats struct {
	StartTime         time.Time
	EndTime           time.Time
	TotalRequests     int
	CompletedRequests int
	FailedRequests    int

	// time tracking
	MinDuration   time.Duration
	MaxDuration   time.Duration
	TotalDuration time.Duration

	// streaming percentile calculations
	Percentiles *PercentileCalculator

	// network stats
	BytesSent int64
	BytesRecv int64

	// error tracking
	Errors map[string]int64 // error code -> count

	// system metrics
	CPUUsage    float64 // percentage
	MemoryUsage uint64  // bytes
	// contains filtered or unexported fields
}

LoadTestStats holds aggregated stats about the load test

func NewLoadTestStats

func NewLoadTestStats(totalRequests int) *LoadTestStats

NewLoadTestStats creates a new LoadTestStats instance

func (*LoadTestStats) GetSnapshot

func (s *LoadTestStats) GetSnapshot() LoadTestStats

type LoadTestStatsMsg

type LoadTestStatsMsg struct {
	Stats    *LoadTestStats
	Progress float64 // 0.0 to 1.0
}

type PercentileCalculator

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

PercentileCalculator data structure for streaming percentile calculations

func (*PercentileCalculator) Percentile

func (p *PercentileCalculator) Percentile(percentile float64) time.Duration

type Request

type Request struct {
	ID      int64             `json:"id,omitempty"`
	Name    string            `json:"name,omitempty"`
	Method  string            `json:"method"`
	URL     string            `json:"url"`
	Headers map[string]string `json:"headers,omitempty"`
	Body    string            `json:"body,omitempty"`
}

func NewBlankRequest

func NewBlankRequest() *Request

func NewDefaultRequest

func NewDefaultRequest() *Request

func NewRequestWithParams

func NewRequestWithParams(method, url string) *Request

func (*Request) Validate

func (r *Request) Validate() error

type Response

type Response struct {
	StatusCode int           `json:"status_code"`
	Status     string        `json:"status,omitempty"`
	Headers    http.Header   `json:"headers,omitempty"`
	Body       string        `json:"body,omitempty"`
	Duration   time.Duration `json:"duration,omitempty"`
	Error      string        `json:"error,omitempty"`
	RoundTrip  bool          `json:"round_trip,omitempty"`
}

func (*Response) ParseContentType

func (r *Response) ParseContentType() string

type ResultMsg

type ResultMsg struct {
	Response *Response
}

func (*ResultMsg) String

func (r *ResultMsg) String() string

Jump to

Keyboard shortcuts

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