Pārlūkot izejas kodu

增加自动获取所有配置文件方法,增加微服务配置插入删除方法

qdy 1 mēnesi atpakaļ
vecāks
revīzija
f1e8cdd018

+ 12
- 0
model/request/configreq/config_requset_model.go Parādīt failu

@@ -0,0 +1,12 @@
1
+package configreq
2
+
3
+// ConfigRequest 配置参数请求
4
+type ConfigRequest struct {
5
+	YamlRoot     string                  `json:"yaml_boot" binding:"required"`
6
+	ConfigFields map[string]*ConfigField `json:"config_info,omitempty"`
7
+}
8
+
9
+type ConfigField struct {
10
+	YamlName  string `json:"yaml_name," binding:"required"`
11
+	YamlValue string `json:"yaml_value" binding:"required"`
12
+}

+ 36
- 0
model/request/dbreq/db_requset_model.go Parādīt failu

@@ -0,0 +1,36 @@
1
+package dbreq
2
+
3
+// TableRequest 表字典
4
+type TableRequest struct {
5
+	TableName           string `json:"table_name"`
6
+	TableNameCN         string `json:"table_name_cn"`
7
+	Description         string `json:"description"`
8
+	PrimaryKeyFieldName string `json:"primary_key_field_name"`
9
+}
10
+
11
+// TablesRequest 表字典集合
12
+type TablesRequest struct {
13
+	TableNames []*TableRequest `json:"table_names"`
14
+	FieldInfos []*FieldInfo    `json:"field_names"`
15
+}
16
+
17
+// FieldInfo 字段信息
18
+type FieldInfo struct {
19
+	TableName string `json:"table_name"`
20
+	// 字段名称(英文/数据库字段名)
21
+	FieldName string `json:"field_name"`
22
+	// 字段中文名称
23
+	FieldNameCN string `json:"field_name_cn"`
24
+	// 字段描述
25
+	Description string `json:"description"`
26
+	// 字段类型(如:varchar, int, datetime等)
27
+	FieldType string `json:"field_type"`
28
+	// 字段长度/精度
29
+	FieldLength *int `json:"field_length,omitempty"`
30
+	// 是否为主键
31
+	IsPrimaryKey bool `json:"is_primary_key"`
32
+	// 是否允许为空
33
+	IsNullable bool `json:"is_nullable"`
34
+	// 小数位数(对于decimal类型)
35
+	DecimalPlaces *int `json:"decimal_places,omitempty"`
36
+}

+ 14
- 0
model/request/dorisreq/doris_requset_model.go Parādīt failu

@@ -0,0 +1,14 @@
1
+package dorisreq
2
+
3
+// QueryRequest 查询请求
4
+type QueryRequest struct {
5
+	SQL              string                 `json:"sql" binding:"required"`
6
+	Params           map[string]interface{} `json:"params,omitempty"`           //名称参数
7
+	PositionalParams []interface{}          `json:"positionalParams,omitempty"` // 位置参数
8
+	WriterHeader     bool                   `json:"writerHeader,omitempty"`     //如果查询返回cvs格式时候,包含表头还是不包含。true包含。第一行是表头
9
+	AgentUrl         string                 `json:"agentUrl,omitempty"`         //远程服务器地址
10
+	AgentToken       string                 `json:"agentToken,omitempty"`       //远程代理服务器token
11
+	DorisDatabase    string                 `json:"dorisDatabase,omitempty"`    //doris数据库名称
12
+	DorisTable       string                 `json:"dorisTable,omitempty"`       //doris数据库里的表名称
13
+
14
+}

model/request/requset_model.go → model/request/mqreq/mq_requset_model.go Parādīt failu

@@ -1,4 +1,4 @@
1
-package request
1
+package mqreq
2 2
 
3 3
 import (
4 4
 	"time"
@@ -75,64 +75,3 @@ type QueueInfoRequest struct {
75 75
 	ChannelName string `json:"channel_name,omitempty"`
76 76
 	QueueName   string `json:"queue_name,omitempty"`
77 77
 }
78
-
79
-// RabbitMQResult RabbitMQ操作结果
80
-// type RabbitMQResult struct {
81
-// 	Success   bool        `json:"success"`
82
-// 	Error     string      `json:"error,omitempty"`
83
-// 	Data      interface{} `json:"data,omitempty"`
84
-// 	Message   string      `json:"message,omitempty"`
85
-// 	Time      string      `json:"time"`
86
-// 	Exchange  string      `json:"exchange,omitempty"`
87
-// 	Queue     string      `json:"queue,omitempty"`
88
-// 	MessageID string      `json:"message_id,omitempty"`
89
-// 	QueueInfo interface{} `json:"queue_info,omitempty"`
90
-// }
91
-
92
-// QueryRequest 查询请求
93
-type QueryRequest struct {
94
-	SQL              string                 `json:"sql" binding:"required"`
95
-	Params           map[string]interface{} `json:"params,omitempty"`           //名称参数
96
-	PositionalParams []interface{}          `json:"positionalParams,omitempty"` // 位置参数
97
-	WriterHeader     bool                   `json:"writerHeader,omitempty"`     //如果查询返回cvs格式时候,包含表头还是不包含。true包含。第一行是表头
98
-	AgentUrl         string                 `json:"agentUrl,omitempty"`         //远程服务器地址
99
-	AgentToken       string                 `json:"agentToken,omitempty"`       //远程代理服务器token
100
-	DorisDatabase    string                 `json:"dorisDatabase,omitempty"`    //doris数据库名称
101
-	DorisTable       string                 `json:"dorisTable,omitempty"`       //doris数据库里的表名称
102
-
103
-}
104
-
105
-// TableRequest 表字典
106
-type TableRequest struct {
107
-	TableName           string `json:"table_name"`
108
-	TableNameCN         string `json:"table_name_cn"`
109
-	Description         string `json:"description"`
110
-	PrimaryKeyFieldName string `json:"primary_key_field_name"`
111
-}
112
-
113
-// TablesRequest 表字典集合
114
-type TablesRequest struct {
115
-	TableNames []*TableRequest `json:"table_names"`
116
-	FieldInfos []*FieldInfo    `json:"field_names"`
117
-}
118
-
119
-// FieldInfo 字段信息
120
-type FieldInfo struct {
121
-	TableName string `json:"table_name"`
122
-	// 字段名称(英文/数据库字段名)
123
-	FieldName string `json:"field_name"`
124
-	// 字段中文名称
125
-	FieldNameCN string `json:"field_name_cn"`
126
-	// 字段描述
127
-	Description string `json:"description"`
128
-	// 字段类型(如:varchar, int, datetime等)
129
-	FieldType string `json:"field_type"`
130
-	// 字段长度/精度
131
-	FieldLength *int `json:"field_length,omitempty"`
132
-	// 是否为主键
133
-	IsPrimaryKey bool `json:"is_primary_key"`
134
-	// 是否允许为空
135
-	IsNullable bool `json:"is_nullable"`
136
-	// 小数位数(对于decimal类型)
137
-	DecimalPlaces *int `json:"decimal_places,omitempty"`
138
-}

util/crypto_service.go → util/crypto/crypto_service.go Parādīt failu

@@ -1,4 +1,4 @@
1
-package util
1
+package crypto
2 2
 
3 3
 import (
4 4
 	"crypto/aes"

util/jwt_util.go → util/jwt/jwt_util.go Parādīt failu

@@ -1,4 +1,4 @@
1
-package util
1
+package jwt
2 2
 
3 3
 import (
4 4
 	"fmt"

util/modle_util.go → util/model/modle_util.go Parādīt failu

@@ -1,4 +1,4 @@
1
-package util
1
+package model
2 2
 
3 3
 import (
4 4
 	"reflect"

+ 120
- 0
util/valid/string_valid.go Parādīt failu

@@ -0,0 +1,120 @@
1
+package valid
2
+
3
+import (
4
+	"encoding/json"
5
+	"fmt"
6
+	"strconv"
7
+	"strings"
8
+)
9
+
10
+// ValidateAndConvert 验证并转换配置值(纯函数模式)
11
+func ValidateAndConvert(fieldType, yamlValue string) (string, error) {
12
+	if fieldType == "" {
13
+		// 如果没有指定类型,按字符串处理
14
+		return yamlValue, nil
15
+	}
16
+
17
+	switch fieldType {
18
+	case "bool":
19
+		return ValidateBool(yamlValue)
20
+	case "int":
21
+		return ValidateInt(yamlValue)
22
+	case "string":
23
+		return ValidateString(yamlValue)
24
+	case "uint64":
25
+		return ValidateUint64(yamlValue)
26
+	default:
27
+		// 检查是否是 map 类型
28
+		if strings.HasPrefix(fieldType, "map[") {
29
+			return ValidateMap(fieldType, yamlValue)
30
+		}
31
+		// 未知类型,按原样返回(可能是自定义类型)
32
+		return yamlValue, nil
33
+	}
34
+}
35
+
36
+// validateBool 验证布尔值(纯函数模式)
37
+func ValidateBool(value string) (string, error) {
38
+	if value == "" {
39
+		return "false", nil // 空值默认为 false
40
+	}
41
+
42
+	// 支持多种布尔表示形式
43
+	switch strings.ToLower(value) {
44
+	case "true", "1", "yes", "y", "on":
45
+		return "true", nil
46
+	case "false", "0", "no", "n", "off":
47
+		return "false", nil
48
+	default:
49
+		// 尝试解析
50
+		if b, err := strconv.ParseBool(value); err == nil {
51
+			return strconv.FormatBool(b), nil
52
+		}
53
+		return "", fmt.Errorf("无效的布尔值: %s,可接受值: true/false, 1/0, yes/no, on/off", value)
54
+	}
55
+}
56
+
57
+// validateInt 验证整数值(纯函数模式)
58
+func ValidateInt(value string) (string, error) {
59
+	if value == "" {
60
+		return "0", nil // 空值默认为 0
61
+	}
62
+
63
+	// 尝试解析为整数
64
+	_, err := strconv.Atoi(value)
65
+	if err != nil {
66
+		// 也尝试解析为浮点数然后取整
67
+		if f, err := strconv.ParseFloat(value, 64); err == nil {
68
+			return strconv.Itoa(int(f)), nil
69
+		}
70
+		return "", fmt.Errorf("无效的整数值: %s", value)
71
+	}
72
+
73
+	return value, nil
74
+}
75
+
76
+// validateUint64 验证无符号64位整数(纯函数模式)
77
+func ValidateUint64(value string) (string, error) {
78
+	if value == "" {
79
+		return "0", nil // 空值默认为 0
80
+	}
81
+
82
+	// 尝试解析为 uint64
83
+	_, err := strconv.ParseUint(value, 10, 64)
84
+	if err != nil {
85
+		return "", fmt.Errorf("无效的uint64值: %s", value)
86
+	}
87
+
88
+	return value, nil
89
+}
90
+
91
+// validateString 验证字符串(纯函数模式)
92
+func ValidateString(value string) (string, error) {
93
+	// 字符串类型不需要特殊验证
94
+	return value, nil
95
+}
96
+
97
+// validateMap 验证 map 类型(纯函数模式)
98
+func ValidateMap(fieldType, value string) (string, error) {
99
+	if value == "" {
100
+		return "{}", nil // 空值返回空对象
101
+	}
102
+
103
+	// 检查是否是期望的 map[string]*subconfigs.DbConfig 类型
104
+	if fieldType != "map[string]*subconfigs.DbConfig" {
105
+		return "", fmt.Errorf("不支持的map类型: %s", fieldType)
106
+	}
107
+
108
+	// 验证是否为有效的 JSON
109
+	if !IsValidJSON(value) {
110
+		return "", fmt.Errorf("map类型需要有效的JSON格式")
111
+	}
112
+
113
+	return value, nil
114
+}
115
+
116
+// isValidJSON 检查是否为有效的 JSON(纯函数模式)
117
+func IsValidJSON(s string) bool {
118
+	var js interface{}
119
+	return json.Unmarshal([]byte(s), &js) == nil
120
+}

Notiek ielāde…
Atcelt
Saglabāt