ends article branch
This commit is contained in:
@@ -58,7 +58,7 @@ func setupKnockRoutes(api *gin.RouterGroup) {
|
||||
c.JSON(400, gin.H{"error": "targets is required in inline mode"})
|
||||
return
|
||||
}
|
||||
config, err := parseInlineTargetsWithWait(req.Targets, req.Delay, req.WaitConnection)
|
||||
config, err := parseInlineTargetsWithWait(req.Targets, req.Delay, req.WaitConnection, req.Gateway)
|
||||
if err != nil {
|
||||
c.JSON(400, gin.H{"error": fmt.Sprintf("invalid targets: %v", err)})
|
||||
return
|
||||
@@ -81,7 +81,7 @@ func setupKnockRoutes(api *gin.RouterGroup) {
|
||||
}
|
||||
|
||||
// parseInlineTargetsWithWait парсит inline строку целей в Config с поддержкой waitConnection
|
||||
func parseInlineTargetsWithWait(targets, delay string, waitConnection bool) (internal.Config, error) {
|
||||
func parseInlineTargetsWithWait(targets, delay string, waitConnection bool, gateway string) (internal.Config, error) {
|
||||
var config internal.Config
|
||||
|
||||
// Парсим targets
|
||||
@@ -93,13 +93,18 @@ func parseInlineTargetsWithWait(targets, delay string, waitConnection bool) (int
|
||||
}
|
||||
|
||||
parts := strings.Split(targetStr, ":")
|
||||
if len(parts) != 3 {
|
||||
return config, fmt.Errorf("invalid target format: %s (expected protocol:host:port)", targetStr)
|
||||
if !(len(parts) == 3 || len(parts) == 4) {
|
||||
return config, fmt.Errorf("invalid target format: %s (expected protocol:host:port or protocol:host:port:gateway)", targetStr)
|
||||
}
|
||||
|
||||
protocol := strings.TrimSpace(parts[0])
|
||||
host := strings.TrimSpace(parts[1])
|
||||
portStr := strings.TrimSpace(parts[2])
|
||||
|
||||
|
||||
if len(parts) == 4 {
|
||||
gateway = strings.TrimSpace(parts[3])
|
||||
}
|
||||
|
||||
if protocol != "tcp" && protocol != "udp" {
|
||||
return config, fmt.Errorf("unsupported protocol: %s (only tcp/udp supported)", protocol)
|
||||
@@ -128,6 +133,7 @@ func parseInlineTargetsWithWait(targets, delay string, waitConnection bool) (int
|
||||
Ports: []int{port},
|
||||
Delay: targetDelay,
|
||||
WaitConnection: waitConnection,
|
||||
Gateway: gateway,
|
||||
}
|
||||
|
||||
config.Targets = append(config.Targets, target)
|
||||
|
Reference in New Issue
Block a user