mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-22 09:10:25 +08:00
优化数据库节点管理
This commit is contained in:
34
internal/web/actions/default/db/dbnodeutils/utils.go
Normal file
34
internal/web/actions/default/db/dbnodeutils/utils.go
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package dbnodeutils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
// InitNode 初始化指标信息
|
||||
func InitNode(parent *actionutils.ParentAction, nodeId int64) (*pb.DBNode, error) {
|
||||
client, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := client.DBNodeRPC().FindEnabledDBNode(parent.AdminContext(), &pb.FindEnabledDBNodeRequest{DbNodeId: nodeId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var node = resp.DbNode
|
||||
if node == nil {
|
||||
return nil, errors.New("not found db node with id '" + types.String(nodeId) + "'")
|
||||
}
|
||||
parent.Data["node"] = maps.Map{
|
||||
"id": node.Id,
|
||||
"name": node.Name,
|
||||
}
|
||||
return node, nil
|
||||
}
|
||||
Reference in New Issue
Block a user