refactor: 标准化项目结构 frontend/ + backend/ + SQLite + run.sh
- 目录重构: app/ -> frontend/,与 backend/ 并列 - 数据库: 默认 SQLite(零配置),修复 DSN() bug - run.sh: 一键启动前后端,支持 start/stop/restart/status - Makefile: install/dev/build/lint/clean 快捷命令 - vite.config.ts: 配置 dev server 端口 5173 + API 代理到 8080 - config.yaml: SQLite 默认配置,开箱即用 - docs/: 完整开发文档(项目结构/API/数据库/规范/部署) - 修复: GORM foreign key 关联声明 - 修复: go get gorm.io/driver/sqlite 依赖
This commit is contained in:
1 parent
7d6674bddd
commit
97c4207ff8
132 files changed
+1572
-34
No files matched your search
@@ -1,6 +1,8 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
@@ -60,7 +62,8 @@ func Load() *Config {
|
||||
viper.SetDefault("mode", "development")
|
||||
viper.SetDefault("port", "8080")
|
||||
viper.SetDefault("log_level", "info")
|
||||
viper.SetDefault("database.driver", "mysql")
|
||||
viper.SetDefault("database.driver", "sqlite")
|
||||
viper.SetDefault("database.dbname", "data/aiops.db")
|
||||
viper.SetDefault("database.host", "localhost")
|
||||
viper.SetDefault("database.port", 3306)
|
||||
viper.SetDefault("database.charset", "utf8mb4")
|
||||
@@ -90,7 +93,11 @@ func Load() *Config {
|
||||
// DSN 返回数据库连接字符串
|
||||
func (d *DatabaseConfig) DSN() string {
|
||||
if d.Driver == "mysql" {
|
||||
return d.User + ":" + d.Password + "@tcp(" + d.Host + ":" + string(rune(d.Port)) + ")/" + d.DBName + "?charset=" + d.Charset + "&parseTime=True&loc=Local"
|
||||
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=%s&parseTime=True&loc=Local",
|
||||
d.User, d.Password, d.Host, d.Port, d.DBName, d.Charset)
|
||||
}
|
||||
if d.Driver == "sqlite" {
|
||||
return d.DBName
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -44,9 +44,9 @@ type ApprovalProcess struct {
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
// 关联
|
||||
Template *ApprovalTemplate `json:"template,omitempty"`
|
||||
ApplicantUser *User `json:"applicant_user,omitempty"`
|
||||
Steps []ApprovalStep `json:"steps,omitempty"`
|
||||
Template *ApprovalTemplate `gorm:"foreignKey:TemplateID" json:"template,omitempty"`
|
||||
ApplicantUser *User `gorm:"foreignKey:Applicant" json:"applicant_user,omitempty"`
|
||||
Steps []ApprovalStep `gorm:"foreignKey:ProcessID" json:"steps,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
@@ -67,7 +67,7 @@ type ApprovalStep struct {
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
ApproverUser *User `json:"approver_user,omitempty"`
|
||||
ApproverUser *User `gorm:"foreignKey:Approver" json:"approver_user,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
|
||||
Reference in new issue
Block a user