kra/internal/service/system/system_config.go

41 lines
1.1 KiB
Go

package system
import (
"kra/pkg/server"
"github.com/go-kratos/kratos/v2/errors"
"github.com/go-kratos/kratos/v2/transport/http"
)
// SystemConfigService 系统配置服务
type SystemConfigService struct {
diskMountPoints []string
}
// NewSystemConfigService 创建系统配置服务
func NewSystemConfigService() *SystemConfigService {
// 默认磁盘挂载点,可以从配置中读取
return &SystemConfigService{
diskMountPoints: []string{"/"},
}
}
// RegisterRoutes 注册路由
func (s *SystemConfigService) RegisterRoutes(rg *RouterGroup) {
// 读操作(不记录)
rg.Private.POST("/system/getServerInfo", s.handleGetServerInfo)
}
// handleGetServerInfo 获取服务器信息
func (s *SystemConfigService) handleGetServerInfo(ctx http.Context) error {
serverInfo, err := server.GetServerInfo(s.diskMountPoints)
if err != nil {
return errors.InternalServer("GET_SERVER_INFO_FAILED", "获取失败:"+err.Error())
}
return ctx.Result(200, map[string]any{
"code": 0,
"msg": "获取成功",
"data": map[string]any{"server": serverInfo},
})
}