后端重构

This commit is contained in:
Yvan
2026-01-14 14:34:49 +08:00
parent f5f77b32fe
commit 30842b42e5
274 changed files with 39754 additions and 1005 deletions
+1491 -182
View File
File diff suppressed because it is too large Load Diff
+160 -27
View File
@@ -26,6 +26,14 @@ message Bootstrap {
Excel excel = 18;
Cors cors = 19;
Zap zap = 20;
MCP mcp = 21;
Autocode autocode = 22;
Mssql mssql = 23;
Oracle oracle = 24;
Mongo mongo = 25;
repeated SpecializedDB db_list = 26;
repeated Redis redis_list = 27;
repeated DiskList disk_list = 28;
}
message Server {
@@ -60,6 +68,9 @@ message System {
int32 iplimit_time = 7;
string router_prefix = 8;
bool use_strict_auth = 9;
int32 addr = 10;
bool use_mongo = 11;
bool disable_auto_migrate = 12;
}
message Captcha {
@@ -70,48 +81,146 @@ message Captcha {
int32 open_captcha_timeout = 5;
}
message Mysql {
string path = 1;
// GeneralDB contains common database configuration fields
message GeneralDB {
string prefix = 1;
string port = 2;
string config = 3;
string db_name = 4;
string username = 5;
string password = 6;
int32 max_idle_conns = 7;
int32 max_open_conns = 8;
string path = 7;
string engine = 8;
string log_mode = 9;
bool log_zap = 10;
int32 max_idle_conns = 10;
int32 max_open_conns = 11;
bool singular = 12;
bool log_zap = 13;
}
message Mysql {
string prefix = 1;
string path = 2;
string port = 3;
string config = 4;
string db_name = 5;
string username = 6;
string password = 7;
string engine = 8;
int32 max_idle_conns = 9;
int32 max_open_conns = 10;
string log_mode = 11;
bool log_zap = 12;
bool singular = 13;
}
message Pgsql {
string path = 1;
string port = 2;
string config = 3;
string db_name = 4;
string username = 5;
string password = 6;
int32 max_idle_conns = 7;
int32 max_open_conns = 8;
string log_mode = 9;
bool log_zap = 10;
string prefix = 1;
string path = 2;
string port = 3;
string config = 4;
string db_name = 5;
string username = 6;
string password = 7;
string engine = 8;
int32 max_idle_conns = 9;
int32 max_open_conns = 10;
string log_mode = 11;
bool log_zap = 12;
bool singular = 13;
}
message Sqlite {
string path = 1;
string db_name = 2;
int32 max_idle_conns = 3;
int32 max_open_conns = 4;
string log_mode = 5;
bool log_zap = 6;
string prefix = 1;
string path = 2;
string db_name = 3;
string engine = 4;
int32 max_idle_conns = 5;
int32 max_open_conns = 6;
string log_mode = 7;
bool log_zap = 8;
bool singular = 9;
}
message Mssql {
string prefix = 1;
string path = 2;
string port = 3;
string config = 4;
string db_name = 5;
string username = 6;
string password = 7;
string engine = 8;
int32 max_idle_conns = 9;
int32 max_open_conns = 10;
string log_mode = 11;
bool log_zap = 12;
bool singular = 13;
}
message Oracle {
string prefix = 1;
string path = 2;
string port = 3;
string config = 4;
string db_name = 5;
string username = 6;
string password = 7;
string engine = 8;
int32 max_idle_conns = 9;
int32 max_open_conns = 10;
string log_mode = 11;
bool log_zap = 12;
bool singular = 13;
}
// SpecializedDB for db-list configuration
message SpecializedDB {
string type = 1;
string alias_name = 2;
string prefix = 3;
string port = 4;
string config = 5;
string db_name = 6;
string username = 7;
string password = 8;
string path = 9;
string engine = 10;
string log_mode = 11;
int32 max_idle_conns = 12;
int32 max_open_conns = 13;
bool singular = 14;
bool log_zap = 15;
bool disable = 16;
}
message Redis {
bool use_cluster = 1;
string addr = 2;
string password = 3;
int32 db = 4;
repeated string cluster_addrs = 5;
string name = 1;
bool use_cluster = 2;
string addr = 3;
string password = 4;
int32 db = 5;
repeated string cluster_addrs = 6;
}
message Mongo {
string coll = 1;
string options = 2;
string database = 3;
string username = 4;
string password = 5;
string auth_source = 6;
uint64 min_pool_size = 7;
uint64 max_pool_size = 8;
int64 socket_timeout_ms = 9;
int64 connect_timeout_ms = 10;
bool is_zap = 11;
repeated MongoHost hosts = 12;
}
message MongoHost {
string host = 1;
string port = 2;
}
message Local {
@@ -194,6 +303,7 @@ message Email {
bool is_ssl = 5;
string secret = 6;
string nickname = 7;
bool is_login_auth = 8;
}
message Excel {
@@ -224,3 +334,26 @@ message Zap {
bool log_in_console = 8;
int32 retention_day = 9;
}
message Autocode {
string web = 1;
string root = 2;
string server = 3;
string module = 4;
string ai_path = 5;
}
message MCP {
string name = 1;
string version = 2;
string sse_path = 3;
string message_path = 4;
string url_prefix = 5;
int32 addr = 6;
bool separate = 7;
bool enabled = 8;
}
message DiskList {
string mount_point = 1;
}
+231
View File
@@ -10,10 +10,33 @@ var ProviderSet = wire.NewSet(
ProvideServer,
ProvideJWT,
ProvideMysql,
ProvidePgsql,
ProvideSqlite,
ProvideMssql,
ProvideOracle,
ProvideRedis,
ProvideMongo,
ProvideCaptcha,
ProvideSystem,
ProvideUseStrictAuth,
ProvideZapLogger,
ProvideAutocode,
ProvideAutoCodeConfig,
ProvideAutoCodeLLMConfig,
ProvideAutoCodeMCPConfig,
ProvideMCP,
ProvideLocal,
ProvideQiniu,
ProvideMinio,
ProvideAliyunOss,
ProvideTencentCos,
ProvideAwsS3,
ProvideCloudflareR2,
ProvideHuaweiObs,
ProvideEmail,
ProvideExcel,
ProvideCors,
ProvideZap,
)
// ProvideZapLogger 提供zap日志实例
@@ -37,6 +60,36 @@ func ProvideMysql(c *Bootstrap) *Mysql {
return c.Mysql
}
// ProvidePgsql 提供Pgsql配置
func ProvidePgsql(c *Bootstrap) *Pgsql {
return c.Pgsql
}
// ProvideSqlite 提供Sqlite配置
func ProvideSqlite(c *Bootstrap) *Sqlite {
return c.Sqlite
}
// ProvideMssql 提供Mssql配置
func ProvideMssql(c *Bootstrap) *Mssql {
return c.Mssql
}
// ProvideOracle 提供Oracle配置
func ProvideOracle(c *Bootstrap) *Oracle {
return c.Oracle
}
// ProvideRedis 提供Redis配置
func ProvideRedis(c *Bootstrap) *Redis {
return c.Redis
}
// ProvideMongo 提供Mongo配置
func ProvideMongo(c *Bootstrap) *Mongo {
return c.Mongo
}
// ProvideCaptcha 提供Captcha配置
func ProvideCaptcha(c *Bootstrap) *Captcha {
return c.Captcha
@@ -57,3 +110,181 @@ func ProvideUseStrictAuth(c *System) UseStrictAuth {
}
return UseStrictAuth(c.UseStrictAuth)
}
// ProvideAutocode 提供Autocode配置
func ProvideAutocode(c *Bootstrap) *Autocode {
if c.Autocode == nil {
return &Autocode{
Web: "web/src",
Root: "./",
Server: "server",
Module: "kra",
AiPath: "",
}
}
return c.Autocode
}
// AutoCodeConfig 自动代码配置
type AutoCodeConfig struct {
Root string
Server string
Web string
Module string
}
// AutoCodeLLMConfig LLM配置
type AutoCodeLLMConfig struct {
AiPath string
}
// AutoCodeMCPConfig MCP配置
type AutoCodeMCPConfig struct {
Root string
Server string
}
// ProvideAutoCodeConfig 提供AutoCode配置
func ProvideAutoCodeConfig(autocode *Autocode) *AutoCodeConfig {
if autocode == nil {
return &AutoCodeConfig{
Root: "./",
Server: "server",
Web: "web",
Module: "kra",
}
}
return &AutoCodeConfig{
Root: autocode.Root,
Server: autocode.Server,
Web: autocode.Web,
Module: autocode.Module,
}
}
// ProvideAutoCodeLLMConfig 提供AutoCodeLLM配置
func ProvideAutoCodeLLMConfig(autocode *Autocode) *AutoCodeLLMConfig {
if autocode == nil {
return &AutoCodeLLMConfig{
AiPath: "",
}
}
return &AutoCodeLLMConfig{
AiPath: autocode.AiPath,
}
}
// ProvideAutoCodeMCPConfig 提供AutoCodeMCP配置
func ProvideAutoCodeMCPConfig(autocode *Autocode) *AutoCodeMCPConfig {
if autocode == nil {
return &AutoCodeMCPConfig{
Root: "./",
Server: "server",
}
}
return &AutoCodeMCPConfig{
Root: autocode.Root,
Server: autocode.Server,
}
}
// ProvideMCP 提供MCP配置
func ProvideMCP(c *Bootstrap) *MCP {
if c.Mcp == nil {
return &MCP{
Name: "kra-mcp",
Version: "v1.0.0",
SsePath: "/mcp/sse",
MessagePath: "/mcp/message",
UrlPrefix: "",
Addr: 8889,
Separate: false,
Enabled: false,
}
}
return c.Mcp
}
// ProvideLocal 提供Local配置
func ProvideLocal(c *Bootstrap) *Local {
if c.Local == nil {
return &Local{
Path: "uploads/file",
StorePath: "uploads/file",
}
}
return c.Local
}
// ProvideQiniu 提供Qiniu配置
func ProvideQiniu(c *Bootstrap) *Qiniu {
return c.Qiniu
}
// ProvideMinio 提供Minio配置
func ProvideMinio(c *Bootstrap) *Minio {
return c.Minio
}
// ProvideAliyunOss 提供AliyunOss配置
func ProvideAliyunOss(c *Bootstrap) *AliyunOss {
return c.AliyunOss
}
// ProvideTencentCos 提供TencentCos配置
func ProvideTencentCos(c *Bootstrap) *TencentCos {
return c.TencentCos
}
// ProvideAwsS3 提供AwsS3配置
func ProvideAwsS3(c *Bootstrap) *AwsS3 {
return c.AwsS3
}
// ProvideCloudflareR2 提供CloudflareR2配置
func ProvideCloudflareR2(c *Bootstrap) *CloudflareR2 {
return c.CloudflareR2
}
// ProvideHuaweiObs 提供HuaweiObs配置
func ProvideHuaweiObs(c *Bootstrap) *HuaweiObs {
return c.HuaweiObs
}
// ProvideEmail 提供Email配置
func ProvideEmail(c *Bootstrap) *Email {
return c.Email
}
// ProvideExcel 提供Excel配置
func ProvideExcel(c *Bootstrap) *Excel {
if c.Excel == nil {
return &Excel{
Dir: "./resource/excel/",
}
}
return c.Excel
}
// ProvideCors 提供Cors配置
func ProvideCors(c *Bootstrap) *Cors {
return c.Cors
}
// ProvideZap 提供Zap配置
func ProvideZap(c *Bootstrap) *Zap {
if c.Zap == nil {
return &Zap{
Level: "info",
Format: "console",
Prefix: "[kratos-admin]",
Director: "log",
ShowLine: true,
EncodeLevel: "LowercaseColorLevelEncoder",
StacktraceKey: "stacktrace",
LogInConsole: true,
RetentionDay: -1,
}
}
return c.Zap
}