first commit

This commit is contained in:
2025-11-21 16:32:35 +08:00
parent a54424afba
commit ce361482f4
26 changed files with 2445 additions and 0 deletions

39
internal/handler/trace.go Normal file
View File

@@ -0,0 +1,39 @@
package handler
import (
"os/exec"
"strings"
"github.com/gin-gonic/gin"
)
func handleTrace(c *gin.Context, url string, params map[string]interface{}) {
// 执行traceroute命令
cmd := exec.Command("traceroute", url)
output, err := cmd.CombinedOutput()
if err != nil {
c.JSON(200, gin.H{
"type": "ceTrace",
"url": url,
"error": err.Error(),
})
return
}
// 解析输出
lines := strings.Split(string(output), "\n")
traceResult := make([]string, 0)
for _, line := range lines {
line = strings.TrimSpace(line)
if line != "" {
traceResult = append(traceResult, line)
}
}
c.JSON(200, gin.H{
"type": "ceTrace",
"url": url,
"trace_result": traceResult,
})
}