Private
Public Access
1
0
This commit is contained in:
2025-12-30 20:27:35 +08:00
commit 95d3a20292
24 changed files with 2145 additions and 0 deletions

122
app.go Normal file
View File

@@ -0,0 +1,122 @@
package main
import (
"context"
"go-desk/internal/database"
"go-desk/internal/filesystem"
"go-desk/internal/system"
"os"
)
// App 应用结构体
type App struct {
ctx context.Context
db *database.DB
}
// NewApp 创建新的应用实例
func NewApp() *App {
return &App{}
}
// startup 应用启动时调用
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
// 初始化数据库连接
db, err := database.Init()
if err != nil {
println("数据库连接失败:", err.Error())
return
}
a.db = db
}
// QueryUsers 查询用户列表
func (a *App) QueryUsers(keyword string, status int, role int, organid int, page int, pageSize int, sortField string, sortOrder string) (map[string]interface{}, error) {
if a.db == nil {
return map[string]interface{}{
"rows": []interface{}{},
"total": 0,
}, nil
}
return a.db.QueryUsers(keyword, status, role, organid, page, pageSize, sortField, sortOrder)
}
// Greet 测试方法
func (a *App) Greet(name string) string {
return "Hello " + name + ", It's show time!"
}
// GetSystemInfo 获取系统信息
func (a *App) GetSystemInfo() (map[string]interface{}, error) {
return system.GetSystemInfo()
}
// GetCPUInfo 获取 CPU 信息
func (a *App) GetCPUInfo() (map[string]interface{}, error) {
return system.GetCPUInfo()
}
// GetMemoryInfo 获取内存信息
func (a *App) GetMemoryInfo() (map[string]interface{}, error) {
return system.GetMemoryInfo()
}
// GetDiskInfo 获取磁盘信息
func (a *App) GetDiskInfo() ([]map[string]interface{}, error) {
return system.GetDiskInfo()
}
// ReadFile 读取文件
func (a *App) ReadFile(path string) (string, error) {
return filesystem.ReadFile(path)
}
// WriteFile 写入文件
func (a *App) WriteFile(path, content string) error {
return filesystem.WriteFile(path, content)
}
// ListDir 列出目录
func (a *App) ListDir(path string) ([]map[string]interface{}, error) {
return filesystem.ListDir(path)
}
// CreateDir 创建目录
func (a *App) CreateDir(path string) error {
return filesystem.CreateDir(path)
}
// DeletePath 删除文件或目录
func (a *App) DeletePath(path string) error {
return filesystem.DeletePath(path)
}
// GetFileInfo 获取文件信息
func (a *App) GetFileInfo(path string) (map[string]interface{}, error) {
return filesystem.GetFileInfo(path)
}
// GetEnvVars 获取环境变量
func (a *App) GetEnvVars() (map[string]string, error) {
envVars := make(map[string]string)
for _, env := range os.Environ() {
parts := splitEnv(env)
if len(parts) == 2 {
envVars[parts[0]] = parts[1]
}
}
return envVars, nil
}
// splitEnv 分割环境变量字符串key=value
func splitEnv(env string) []string {
for i := 0; i < len(env); i++ {
if env[i] == '=' {
return []string{env[:i], env[i+1:]}
}
}
return []string{env}
}