优化
This commit is contained in:
@@ -7,21 +7,21 @@ import (
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type AuthorityService struct{ uc *biz.AccessUsecase }
|
||||
type AuthorityService struct{ uc *biz.AuthorityUsecase }
|
||||
|
||||
func NewAuthorityService(uc *biz.AccessUsecase) *AuthorityService {
|
||||
func NewAuthorityService(uc *biz.AuthorityUsecase) *AuthorityService {
|
||||
return &AuthorityService{uc: uc}
|
||||
}
|
||||
|
||||
type PermissionService struct{ uc *biz.AccessUsecase }
|
||||
type PermissionService struct{ uc *biz.PermissionUsecase }
|
||||
|
||||
func NewPermissionService(uc *biz.AccessUsecase) *PermissionService {
|
||||
func NewPermissionService(uc *biz.PermissionUsecase) *PermissionService {
|
||||
return &PermissionService{uc: uc}
|
||||
}
|
||||
|
||||
type AccessControlService struct{ uc *biz.AccessUsecase }
|
||||
type AccessControlService struct{ uc *biz.AccessControlUsecase }
|
||||
|
||||
func NewAccessControlService(uc *biz.AccessUsecase) *AccessControlService {
|
||||
func NewAccessControlService(uc *biz.AccessControlUsecase) *AccessControlService {
|
||||
return &AccessControlService{uc: uc}
|
||||
}
|
||||
|
||||
@@ -111,23 +111,6 @@ func (s *AccessControlService) ContextWithDataScope(ctx context.Context, authori
|
||||
return biz.NewDataScopeContext(ctx, scope), nil
|
||||
}
|
||||
|
||||
func (s *PermissionService) Buttons(ctx context.Context, id uint) ([]map[string]any, error) {
|
||||
items, err := s.uc.Buttons(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]map[string]any, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, map[string]any{"ID": v.ID, "name": v.Name, "desc": v.Description, "sysBaseMenuID": v.MenuID})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (s *PermissionService) SetAuthorityButtons(ctx context.Context, id uint, v map[uint][]uint) error {
|
||||
return s.uc.SetAuthorityButtons(ctx, id, v)
|
||||
}
|
||||
func (s *PermissionService) AuthorityButtonIDs(ctx context.Context, id uint) ([]uint, error) {
|
||||
return s.uc.AuthorityButtonIDs(ctx, id)
|
||||
}
|
||||
func (s *PermissionService) SelectedButtons(ctx context.Context, aid, menuID uint) ([]uint, error) {
|
||||
return s.uc.SelectedButtons(ctx, aid, menuID)
|
||||
}
|
||||
|
||||
+23
-2
@@ -10,11 +10,11 @@ import (
|
||||
)
|
||||
|
||||
type APIService struct {
|
||||
uc *biz.AccessUsecase
|
||||
uc *biz.APIUsecase
|
||||
runtime *conf.Runtime
|
||||
}
|
||||
|
||||
func NewAPIService(uc *biz.AccessUsecase, runtime *conf.Runtime) *APIService {
|
||||
func NewAPIService(uc *biz.APIUsecase, runtime *conf.Runtime) *APIService {
|
||||
return &APIService{uc: uc, runtime: runtime}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,27 @@ func (s *APIService) AllAPI(ctx context.Context, strict bool) ([]*dto.APIRespons
|
||||
return apiResponses(items), nil
|
||||
}
|
||||
|
||||
func (s *APIService) Groups(ctx context.Context) ([]string, map[string]string, error) {
|
||||
items, err := s.AllAPI(ctx, false)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
seen := make(map[string]bool)
|
||||
groups := make([]string, 0)
|
||||
groupAPIMap := make(map[string]string)
|
||||
for _, item := range items {
|
||||
if !seen[item.APIGroup] {
|
||||
seen[item.APIGroup] = true
|
||||
groups = append(groups, item.APIGroup)
|
||||
}
|
||||
parts := strings.Split(item.Path, "/")
|
||||
if len(parts) > 1 {
|
||||
groupAPIMap[parts[1]] = item.APIGroup
|
||||
}
|
||||
}
|
||||
return groups, groupAPIMap, nil
|
||||
}
|
||||
|
||||
func (s *APIService) CreateAPIRequest(ctx context.Context, req *dto.APIRequest) (*dto.APIResponse, error) {
|
||||
value := apiDomain(req)
|
||||
if err := s.uc.CreateAPI(ctx, value); err != nil {
|
||||
|
||||
@@ -11,9 +11,9 @@ type AuditService struct{ uc *biz.AuditUsecase }
|
||||
|
||||
func NewAuditService(uc *biz.AuditUsecase) *AuditService { return &AuditService{uc: uc} }
|
||||
|
||||
type AuditRecorder struct{ uc *biz.AuditUsecase }
|
||||
type AuditRecorder struct{ uc *biz.AuditRecorderUsecase }
|
||||
|
||||
func NewAuditRecorder(uc *biz.AuditUsecase) *AuditRecorder { return &AuditRecorder{uc: uc} }
|
||||
func NewAuditRecorder(uc *biz.AuditRecorderUsecase) *AuditRecorder { return &AuditRecorder{uc: uc} }
|
||||
|
||||
func (s *AuditRecorder) RecordOperation(ctx context.Context, v *biz.OperationRecord) error {
|
||||
return s.uc.RecordOperation(ctx, v)
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
"kra/internal/biz"
|
||||
)
|
||||
|
||||
type LogViewerService struct{ uc *biz.AuditUsecase }
|
||||
type LogViewerService struct{ uc *biz.LogViewerUsecase }
|
||||
|
||||
func NewLogViewerService(uc *biz.AuditUsecase) *LogViewerService {
|
||||
func NewLogViewerService(uc *biz.LogViewerUsecase) *LogViewerService {
|
||||
return &LogViewerService{uc: uc}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,10 @@ type SecurityService struct {
|
||||
securityMu sync.RWMutex
|
||||
securityCache *biz.SecurityConfig
|
||||
cache biz.Cache
|
||||
tokens *TokenService
|
||||
tokens *biz.TokenUsecase
|
||||
}
|
||||
|
||||
func NewSecurityService(uc *biz.SecurityUsecase, runtime *conf.Runtime, cache biz.Cache, tokens *TokenService) *SecurityService {
|
||||
func NewSecurityService(uc *biz.SecurityUsecase, runtime *conf.Runtime, cache biz.Cache, tokens *biz.TokenUsecase) *SecurityService {
|
||||
return &SecurityService{uc: uc, runtime: runtime, cache: cache, tokens: tokens}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/shirou/gopsutil/v4/cpu"
|
||||
"github.com/shirou/gopsutil/v4/disk"
|
||||
"github.com/shirou/gopsutil/v4/mem"
|
||||
)
|
||||
|
||||
func (s *SystemConfigService) ServerInfo() (map[string]any, error) {
|
||||
physicalCores, err := cpu.Counts(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cpuPercent, err := cpu.Percent(200*time.Millisecond, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
memory, err := mem.VirtualMemory()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
diskInfo := make([]map[string]any, 0)
|
||||
for _, mountPoint := range s.DiskMountPoints() {
|
||||
usage, usageErr := disk.Usage(mountPoint)
|
||||
if usageErr != nil {
|
||||
return nil, usageErr
|
||||
}
|
||||
diskInfo = append(diskInfo, map[string]any{"mountPoint": mountPoint, "usedMb": usage.Used / 1024 / 1024, "usedGb": usage.Used / 1024 / 1024 / 1024, "totalMb": usage.Total / 1024 / 1024, "totalGb": usage.Total / 1024 / 1024 / 1024, "usedPercent": int(usage.UsedPercent)})
|
||||
}
|
||||
usedMB, totalMB := memory.Used/1024/1024, memory.Total/1024/1024
|
||||
return map[string]any{
|
||||
"os": map[string]any{"goos": runtime.GOOS, "numCpu": runtime.NumCPU(), "compiler": runtime.Compiler, "goVersion": runtime.Version(), "numGoroutine": runtime.NumGoroutine()},
|
||||
"cpu": map[string]any{"cpus": cpuPercent, "cores": physicalCores},
|
||||
"ram": map[string]any{"usedMb": usedMB, "totalMb": totalMB, "usedPercent": int(memory.UsedPercent)},
|
||||
"disk": diskInfo,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user