feat: 重构前后端架构,添加Go后端和Python Agent服务
- 新增 Go 语言后端服务(server/),包含用户认证、Agent管理、数据库连接等API - 新增 Python Agent 服务(agent/),实现Agent核心逻辑和工具集 - 前端从原生HTML迁移到Vue.js框架(web/src/) - 添加 Docker Compose 支持(docker-compose.yml) - 添加项目架构文档(docs/ARCHITECTURE.md) - 添加环境变量示例(.env.example)和本地启动脚本(start-local.ps1) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
62
server/internal/handler/system_handler.go
Normal file
62
server/internal/handler/system_handler.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"x-agents/server/internal/model"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type SystemHandler struct{}
|
||||
|
||||
func NewSystemHandler() *SystemHandler {
|
||||
return &SystemHandler{}
|
||||
}
|
||||
|
||||
// GetSystemInfo 获取系统信息
|
||||
func (h *SystemHandler) GetSystemInfo(c *gin.Context) {
|
||||
info, err := getSystemInfo()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, info)
|
||||
}
|
||||
|
||||
// getSystemInfo 获取系统信息
|
||||
func getSystemInfo() (*model.SystemInfo, error) {
|
||||
// 获取CPU使用率
|
||||
cpuPercent, err := getCPUPercent()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 获取CPU核心数
|
||||
coreCount, err := getCPUCoreCount()
|
||||
if err != nil {
|
||||
coreCount = 0
|
||||
}
|
||||
|
||||
// 获取CPU型号
|
||||
modelName, err := getCPUModelName()
|
||||
if err != nil {
|
||||
modelName = "Unknown"
|
||||
}
|
||||
|
||||
// 获取内存信息
|
||||
memoryInfo, err := getMemoryInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &model.SystemInfo{
|
||||
CPU: model.CPUInfo{
|
||||
Percent: cpuPercent,
|
||||
CoreCount: coreCount,
|
||||
ModelName: modelName,
|
||||
},
|
||||
Memory: *memoryInfo,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user