修改秒杀
This commit is contained in:
@@ -20,7 +20,7 @@ type Response struct {
|
||||
}
|
||||
|
||||
func main() {
|
||||
const totalBatches = 5 // 固定发送5批请求
|
||||
const totalBatches = 1 // 固定发送5批请求
|
||||
const batchSize = 150 // 每批固定150个请求
|
||||
const interval = 5 * time.Second // 每批请求的时间间隔(可按需调整)
|
||||
var wg sync.WaitGroup
|
||||
@@ -30,7 +30,7 @@ func main() {
|
||||
// 循环发送5批请求,每批对应不同的商品order(stock10000 ~ stock10004)
|
||||
for batch := 1; batch <= totalBatches; batch++ {
|
||||
// 计算当前批次的目标商品order:第1批→stock10000,第2批→stock10001...第5批→stock10004
|
||||
targetOrder := fmt.Sprintf("stock1000%d", batch-1)
|
||||
targetOrder := fmt.Sprintf("stock:1000%d", batch-1)
|
||||
fmt.Printf("=== 开始第 %d 批请求 ===\n", batch)
|
||||
fmt.Printf("当前批次目标商品: %s | 请求数量: %d 个 | 开始时间: %v\n",
|
||||
targetOrder, batchSize, time.Now().Format("15:04:05"))
|
||||
@@ -72,11 +72,6 @@ func main() {
|
||||
fmt.Println("🎉 所有5批请求已全部完成!")
|
||||
}
|
||||
|
||||
type UserRequest1 struct {
|
||||
UserID int `json:"user_id"`
|
||||
Order string `json:"userorder"` // 对应商品标识:stock10000 ~ stock10004
|
||||
}
|
||||
|
||||
// 发送POST请求(接收用户ID和商品order,构造请求体)
|
||||
func sendPostRequest(userID int, order string) (*Response, error) {
|
||||
// 目标接口地址(根据实际部署调整)
|
||||
|
||||
Reference in New Issue
Block a user