loic-go/cmd/start.go
Daniel Sy f02994f32c
fix(#1): 🐛 Fixed application startup
The main process did not get blocked before. Hence a new channel 'TestDone' is added to be closed when the attack is finished.
2025-03-25 19:33:18 +01:00

32 lines
1.1 KiB
Go

package cmd
import (
"fmt"
"time"
"forgejo.edf-bootstrap.cx.fg1.ffm.osc.live/Daniel.Sy/loic-go/pkg/loic"
"github.com/spf13/cobra"
)
var startCmd = &cobra.Command{
Use: "start",
Short: "Start an attack",
Run: func(cmd *cobra.Command, args []string) {
targetURL, _ := cmd.Flags().GetString("target")
concurrency, _ := cmd.Flags().GetInt("concurrency")
duration, _ := cmd.Flags().GetDuration("duration")
rampUp, _ := cmd.Flags().GetDuration("ramp-up")
fmt.Printf("Starting test with target %s, concurrency %d, duration %v, ramp-up %v\n", targetURL, concurrency, duration, rampUp)
loic.StartTest(targetURL, concurrency, duration, rampUp)
<-loic.TestDone
},
}
func init() {
startCmd.Flags().StringP("target", "t", "", "Ziel-URL für den Test (z. B. http://service.cluster.local oder http://example.com)")
startCmd.Flags().IntP("concurrency", "c", 10, "Maximale Anzahl paralleler Anfragen")
startCmd.Flags().DurationP("duration", "d", time.Minute, "Dauer des Tests")
startCmd.Flags().DurationP("ramp-up", "r", 30*time.Second, "Zeit für schrittweise Erhöhung der Last")
startCmd.MarkFlagRequired("target")
rootCmd.AddCommand(startCmd)
}