Initial commit (code only without large binaries)

This commit is contained in:
robin
2026-02-15 18:58:44 +08:00
commit 35df75498f
9442 changed files with 1495866 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
package db
import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/db/dbnodeutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type CleanAction struct {
actionutils.ParentAction
}
func (this *CleanAction) Init() {
this.Nav("", "", "clean")
}
func (this *CleanAction) RunGet(params struct {
NodeId int64
}) {
_, err := dbnodeutils.InitNode(this.Parent(), params.NodeId)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["nodeId"] = params.NodeId
this.Show()
}
func (this *CleanAction) RunPost(params struct {
NodeId int64
Must *actions.Must
}) {
tablesResp, err := this.RPC().DBNodeRPC().FindAllDBNodeTables(this.AdminContext(), &pb.FindAllDBNodeTablesRequest{
DbNodeId: params.NodeId,
})
if err != nil {
this.Fail("查询数据时出错了:" + err.Error())
}
tableMaps := []maps.Map{}
for _, table := range tablesResp.DbNodeTables {
if !table.IsBaseTable || (!table.CanClean && !table.CanDelete) {
continue
}
tableMaps = append(tableMaps, maps.Map{
"name": table.Name,
"rows": table.Rows,
"size": numberutils.FormatBytes(table.DataLength + table.IndexLength),
"canDelete": table.CanDelete,
"canClean": table.CanClean,
"comment": table.Comment,
})
}
this.Data["tables"] = tableMaps
this.Success()
}

View File

@@ -0,0 +1,173 @@
//go:build plus
package db
import (
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
"strings"
"time"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/iwind/TeaGo/actions"
)
const clickhouseConfigCode = "clickhouseConfig"
type ClickHouseAction struct {
actionutils.ParentAction
}
func (this *ClickHouseAction) Init() {
this.Nav("db", "db", "clickhouse")
}
func (this *ClickHouseAction) RunGet(params struct{}) {
this.Data["mainTab"] = "clickhouse"
resp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: clickhouseConfigCode})
if err != nil {
this.ErrorPage(err)
return
}
cfg := &systemconfigs.ClickHouseSetting{Port: 8443, Database: "default", Scheme: "https"}
if len(resp.ValueJSON) > 0 {
_ = json.Unmarshal(resp.ValueJSON, cfg)
}
if cfg.Port <= 0 {
cfg.Port = 8443
}
if cfg.Database == "" {
cfg.Database = "default"
}
if strings.TrimSpace(cfg.Scheme) == "" {
cfg.Scheme = "https"
}
this.Data["config"] = map[string]interface{}{
"host": cfg.Host,
"port": cfg.Port,
"user": cfg.User,
"password": cfg.Password,
"database": cfg.Database,
"scheme": cfg.Scheme,
}
// 自动检测连接状态
connStatus := "unconfigured" // unconfigured / connected / disconnected
connError := ""
if strings.TrimSpace(cfg.Host) != "" {
connStatus, connError = this.probeClickHouse(cfg)
}
this.Data["connStatus"] = connStatus
this.Data["connError"] = connError
this.Show()
}
func (this *ClickHouseAction) RunPost(params struct {
Host string
Port int
User string
Password string
Database string
Scheme string
Must *actions.Must
}) {
defer this.CreateLogInfo(codes.DBNode_LogUpdateDBNode, 0)
if params.Database == "" {
params.Database = "default"
}
if params.Scheme != "http" {
params.Scheme = "https"
}
if params.Port <= 0 {
params.Port = 8443
}
password := params.Password
if password == "" {
resp, _ := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: clickhouseConfigCode})
if len(resp.ValueJSON) > 0 {
var old systemconfigs.ClickHouseSetting
if json.Unmarshal(resp.ValueJSON, &old) == nil {
password = old.Password
}
}
}
cfg := &systemconfigs.ClickHouseSetting{
Host: params.Host,
Port: params.Port,
User: params.User,
Password: password,
Database: params.Database,
Scheme: params.Scheme,
TLSSkipVerify: true,
TLSServerName: "",
}
valueJSON, err := json.Marshal(cfg)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
Code: clickhouseConfigCode,
ValueJSON: valueJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}
// probeClickHouse 快速检测 ClickHouse 连接状态SELECT 1
func (this *ClickHouseAction) probeClickHouse(cfg *systemconfigs.ClickHouseSetting) (status string, errMsg string) {
scheme := strings.ToLower(strings.TrimSpace(cfg.Scheme))
if scheme == "" {
scheme = "https"
}
port := cfg.Port
if port <= 0 {
port = 8443
}
db := cfg.Database
if db == "" {
db = "default"
}
testURL := fmt.Sprintf("%s://%s:%d/?query=SELECT+1&database=%s", scheme, cfg.Host, port, db)
transport := &http.Transport{}
if scheme == "https" {
transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
}
client := &http.Client{
Timeout: 3 * time.Second,
Transport: transport,
}
req, err := http.NewRequest(http.MethodGet, testURL, nil)
if err != nil {
return "disconnected", err.Error()
}
if cfg.User != "" || cfg.Password != "" {
req.SetBasicAuth(cfg.User, cfg.Password)
}
resp, err := client.Do(req)
if err != nil {
return "disconnected", err.Error()
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "disconnected", fmt.Sprintf("HTTP %d", resp.StatusCode)
}
return "connected", ""
}

View File

@@ -0,0 +1,33 @@
//go:build !plus
package db
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
)
type ClickHouseAction struct {
actionutils.ParentAction
}
func (this *ClickHouseAction) Init() {
this.Nav("db", "db", "clickhouse")
}
func (this *ClickHouseAction) RunGet(params struct{}) {
this.Data["mainTab"] = "clickhouse"
this.Data["config"] = map[string]interface{}{
"host": "", "port": 8443, "user": "", "password": "", "database": "default", "scheme": "https",
}
this.Show()
}
func (this *ClickHouseAction) RunPost(params struct {
Host string
Port int
User string
Password string
Database string
}) {
this.Fail("请使用商业版以在页面上配置 ClickHouse")
}

View File

@@ -0,0 +1,68 @@
package db
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
)
type CreatePopupAction struct {
actionutils.ParentAction
}
func (this *CreatePopupAction) Init() {
this.Nav("", "", "")
}
func (this *CreatePopupAction) RunGet(params struct{}) {
this.Show()
}
func (this *CreatePopupAction) RunPost(params struct {
Name string
Host string
Port int32
Database string
Username string
Password string
Description string
IsOn bool
Must *actions.Must
}) {
params.Must.
Field("name", params.Name).
Require("请输入节点名称").
Field("host", params.Host).
Require("请输入主机地址").
Field("port", params.Port).
Gt(0, "请输入正确的数据库端口").
Lt(65535, "请输入正确的数据库端口").
Field("database", params.Database).
Require("请输入数据库名称").
Field("username", params.Username).
Require("请输入连接数据库的用户名")
createResp, err := this.RPC().DBNodeRPC().CreateDBNode(this.AdminContext(), &pb.CreateDBNodeRequest{
IsOn: params.IsOn,
Name: params.Name,
Description: params.Description,
Host: params.Host,
Port: params.Port,
Database: params.Database,
Username: params.Username,
Password: params.Password,
Charset: "", // 暂时不能修改
})
if err != nil {
this.ErrorPage(err)
return
}
// 创建日志
defer this.CreateLogInfo(codes.DBNode_LogCreateDBNode, createResp.DbNodeId)
this.Success()
}

View 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
}

View File

@@ -0,0 +1,26 @@
package db
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type DeleteAction struct {
actionutils.ParentAction
}
func (this *DeleteAction) RunPost(params struct {
NodeId int64
}) {
// 创建日志
defer this.CreateLogInfo(codes.DBNode_LogDeleteDBNode, params.NodeId)
_, err := this.RPC().DBNodeRPC().DeleteDBNode(this.AdminContext(), &pb.DeleteDBNodeRequest{DbNodeId: params.NodeId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,28 @@
package db
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type DeleteTableAction struct {
actionutils.ParentAction
}
func (this *DeleteTableAction) RunPost(params struct {
NodeId int64
Table string
}) {
defer this.CreateLogInfo(codes.DBNode_LogDeleteTable, params.NodeId, params.Table)
_, err := this.RPC().DBNodeRPC().DeleteDBNodeTable(this.AdminContext(), &pb.DeleteDBNodeTableRequest{
DbNodeId: params.NodeId,
DbNodeTable: params.Table,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,28 @@
package db
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/iwind/TeaGo/actions"
"net/http"
)
type Helper struct {
helpers.LangHelper
}
func (this *Helper) BeforeAction(action *actions.ActionObject) {
if action.Request.Method != http.MethodGet {
return
}
action.Data["teaMenu"] = "db"
var selectedTabbar = action.Data["mainTab"]
var tabbar = actionutils.NewTabbar()
tabbar.Add(this.Lang(action, codes.DBNode_TabNodes), "", "/db", "", selectedTabbar == "db")
tabbar.Add(this.Lang(action, codes.DBNode_TabClickHouse), "", "/db/clickhouse", "", selectedTabbar == "clickhouse")
actionutils.SetTabbar(action, tabbar)
}

View File

@@ -0,0 +1,57 @@
package db
import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("db", "db", "")
}
func (this *IndexAction) RunGet(params struct{}) {
countResp, err := this.RPC().DBNodeRPC().CountAllEnabledDBNodes(this.AdminContext(), &pb.CountAllEnabledDBNodesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
count := countResp.Count
page := this.NewPage(count)
listResp, err := this.RPC().DBNodeRPC().ListEnabledDBNodes(this.AdminContext(), &pb.ListEnabledDBNodesRequest{
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
nodeMaps := []maps.Map{}
for _, node := range listResp.DbNodes {
nodeMaps = append(nodeMaps, maps.Map{
"id": node.Id,
"isOn": node.IsOn,
"name": node.Name,
"host": node.Host,
"port": node.Port,
"database": node.Database,
"status": maps.Map{
"isOk": node.Status.IsOk,
"error": node.Status.Error,
"size": numberutils.FormatBytes(node.Status.Size),
"version": node.Status.Version,
},
})
}
this.Data["nodes"] = nodeMaps
this.Data["page"] = page.AsHTML()
this.Show()
}

View File

@@ -0,0 +1,31 @@
package db
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/settingutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeSetting)).
Helper(new(Helper)).
Helper(settingutils.NewAdvancedHelper("dbNodes")).
Prefix("/db").
Get("", new(IndexAction)).
GetPost("/createPopup", new(CreatePopupAction)).
GetPost("/update", new(UpdateAction)).
Post("/delete", new(DeleteAction)).
GetPost("/clean", new(CleanAction)).
Post("/deleteTable", new(DeleteTableAction)).
Post("/truncateTable", new(TruncateTableAction)).
Get("/node", new(NodeAction)).
Get("/logs", new(LogsAction)).
Post("/status", new(StatusAction)).
GetPost("/clickhouse", new(ClickHouseAction)).
Post("/testClickhouse", new(TestClickHouseAction)).
EndAll()
})
}

View File

@@ -0,0 +1,86 @@
package db
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/db/dbnodeutils"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type LogsAction struct {
actionutils.ParentAction
}
func (this *LogsAction) Init() {
this.Nav("", "", "log")
}
func (this *LogsAction) RunGet(params struct {
NodeId int64
DayFrom string
DayTo string
Keyword string
Level string
}) {
_, err := dbnodeutils.InitNode(this.Parent(), params.NodeId)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["nodeId"] = params.NodeId
this.Data["dayFrom"] = params.DayFrom
this.Data["dayTo"] = params.DayTo
this.Data["keyword"] = params.Keyword
this.Data["level"] = params.Level
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
Role: nodeconfigs.NodeRoleDatabase,
NodeId: params.NodeId,
DayFrom: params.DayFrom,
DayTo: params.DayTo,
Keyword: params.Keyword,
Level: params.Level,
})
if err != nil {
this.ErrorPage(err)
return
}
count := countResp.Count
page := this.NewPage(count, 20)
logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
NodeId: params.NodeId,
Role: nodeconfigs.NodeRoleDatabase,
DayFrom: params.DayFrom,
DayTo: params.DayTo,
Keyword: params.Keyword,
Level: params.Level,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
logs := []maps.Map{}
for _, log := range logsResp.NodeLogs {
logs = append(logs, maps.Map{
"tag": log.Tag,
"description": log.Description,
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
"level": log.Level,
"isToday": timeutil.FormatTime("Y-m-d", log.CreatedAt) == timeutil.Format("Y-m-d"),
})
}
this.Data["logs"] = logs
this.Data["page"] = page.AsHTML()
this.Show()
}

View File

@@ -0,0 +1,42 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package db
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/db/dbnodeutils"
"github.com/iwind/TeaGo/maps"
"strings"
)
type NodeAction struct {
actionutils.ParentAction
}
func (this *NodeAction) Init() {
this.Nav("", "", "node")
}
func (this *NodeAction) RunGet(params struct {
NodeId int64
}) {
node, err := dbnodeutils.InitNode(this.Parent(), params.NodeId)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["node"] = maps.Map{
"id": node.Id,
"isOn": node.IsOn,
"name": node.Name,
"database": node.Database,
"host": node.Host,
"port": node.Port,
"username": node.Username,
"password": strings.Repeat("*", len(node.Password)),
"description": node.Description,
}
this.Show()
}

View File

@@ -0,0 +1,38 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package db
import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type StatusAction struct {
actionutils.ParentAction
}
func (this *StatusAction) RunPost(params struct {
NodeId int64
}) {
statusResp, err := this.RPC().DBNodeRPC().CheckDBNodeStatus(this.AdminContext(), &pb.CheckDBNodeStatusRequest{DbNodeId: params.NodeId})
if err != nil {
this.ErrorPage(err)
return
}
var status = statusResp.DbNodeStatus
if status != nil {
this.Data["status"] = maps.Map{
"isOk": status.IsOk,
"error": status.Error,
"size": numberutils.FormatBytes(status.Size),
"version": status.Version,
}
} else {
this.Data["status"] = nil
}
this.Success()
}

View File

@@ -0,0 +1,92 @@
//go:build plus
package db
import (
"crypto/tls"
"fmt"
"io"
"net/http"
"strings"
"time"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
)
type TestClickHouseAction struct {
actionutils.ParentAction
}
func (this *TestClickHouseAction) Init() {
this.Nav("db", "db", "clickhouse")
}
func (this *TestClickHouseAction) RunPost(params struct {
Host string
Port int
User string
Password string
Database string
Scheme string
Must *actions.Must
}) {
params.Must.
Field("host", params.Host).
Require("请输入 ClickHouse 连接地址")
if params.Database == "" {
params.Database = "default"
}
scheme := "https"
if strings.EqualFold(params.Scheme, "http") {
scheme = "http"
}
if params.Port <= 0 {
params.Port = 8443
}
// 构造测试请求
testURL := fmt.Sprintf("%s://%s:%d/?query=SELECT+1&database=%s",
scheme, params.Host, params.Port, params.Database)
transport := &http.Transport{}
if scheme == "https" {
transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
}
client := &http.Client{
Timeout: 5 * time.Second,
Transport: transport,
}
req, err := http.NewRequest(http.MethodGet, testURL, nil)
if err != nil {
this.Fail("请求构造失败: " + err.Error())
return
}
if params.User != "" || params.Password != "" {
req.SetBasicAuth(params.User, params.Password)
}
resp, err := client.Do(req)
if err != nil {
this.Fail("连接失败: " + err.Error())
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
msg := strings.TrimSpace(string(body))
if len(msg) > 200 {
msg = msg[:200] + "..."
}
this.Fail(fmt.Sprintf("ClickHouse 返回 HTTP %d: %s", resp.StatusCode, msg))
return
}
this.Success()
}

View File

@@ -0,0 +1,23 @@
//go:build !plus
package db
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
)
type TestClickHouseAction struct {
actionutils.ParentAction
}
func (this *TestClickHouseAction) Init() {
this.Nav("db", "db", "clickhouse")
}
func (this *TestClickHouseAction) RunPost(params struct {
Host string
Must *actions.Must
}) {
this.Fail("请使用商业版以测试 ClickHouse 连接")
}

View File

@@ -0,0 +1,28 @@
package db
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type TruncateTableAction struct {
actionutils.ParentAction
}
func (this *TruncateTableAction) RunPost(params struct {
NodeId int64
Table string
}) {
defer this.CreateLogInfo(codes.DBNode_LogTruncateTable, params.NodeId, params.Table)
_, err := this.RPC().DBNodeRPC().TruncateDBNodeTable(this.AdminContext(), &pb.TruncateDBNodeTableRequest{
DbNodeId: params.NodeId,
DbNodeTable: params.Table,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,98 @@
package db
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type UpdateAction struct {
actionutils.ParentAction
}
func (this *UpdateAction) Init() {
this.Nav("", "", "update")
}
func (this *UpdateAction) RunGet(params struct {
NodeId int64
}) {
nodeResp, err := this.RPC().DBNodeRPC().FindEnabledDBNode(this.AdminContext(), &pb.FindEnabledDBNodeRequest{DbNodeId: params.NodeId})
if err != nil {
this.ErrorPage(err)
return
}
node := nodeResp.DbNode
if node == nil {
this.NotFound("dbNode", params.NodeId)
return
}
this.Data["node"] = maps.Map{
"id": node.Id,
"isOn": node.IsOn,
"name": node.Name,
"description": node.Description,
"host": node.Host,
"port": node.Port,
"username": node.Username,
"password": node.Password,
"database": node.Database,
}
this.Show()
}
func (this *UpdateAction) RunPost(params struct {
NodeId int64
Name string
Host string
Port int32
Database string
Username string
Password string
Description string
IsOn bool
Must *actions.Must
}) {
// 创建日志
defer this.CreateLogInfo(codes.DBNode_LogUpdateDBNode, params.NodeId)
params.Must.
Field("name", params.Name).
Require("请输入节点名称").
Field("host", params.Host).
Require("请输入主机地址").
Field("port", params.Port).
Gt(0, "请输入正确的数据库端口").
Lt(65535, "请输入正确的数据库端口").
Field("database", params.Database).
Require("请输入数据库名称").
Field("username", params.Username).
Require("请输入连接数据库的用户名")
_, err := this.RPC().DBNodeRPC().UpdateDBNode(this.AdminContext(), &pb.UpdateDBNodeRequest{
DbNodeId: params.NodeId,
IsOn: params.IsOn,
Name: params.Name,
Description: params.Description,
Host: params.Host,
Port: params.Port,
Database: params.Database,
Username: params.Username,
Password: params.Password,
Charset: "", // 暂时不能修改
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}