feat(model): 新增基础数据模型与路由配置

- 新增 BaseModel 结构体,包含统一主键和时间字段
- 定义 JanusProvider、JanusModel、Channel、APIKey 四个业务模型结构
- 引入 Status 枚举表示启用/禁用状态
- 完成对应数据库建表 SQL 迁移脚本
- 新增 router 包及 API 健康检查路由注册实现
- 优化 main.go,使用 router 包统一路由注册管理
- 补充模型中字段的 GORM 和 JSON 标签规范
This commit is contained in:
yangzhaohan
2026-07-14 23:36:41 +08:00
parent 8ef79eb5f8
commit 0794474c04
10 changed files with 496 additions and 5 deletions
+23
View File
@@ -0,0 +1,23 @@
package model
import (
"time"
"synoth.com/janus/internal/core"
"synoth.com/janus/internal/enum"
)
// APIKey 调用方认证密钥
type APIKey struct {
core.BaseModel
// Key API密钥字符串
Key string `gorm:"uniqueIndex;size:64;not null" json:"key"`
// Name 密钥名称/用途描述
Name string `gorm:"size:100;not null" json:"name"`
// RateLimit 每分钟请求数上限
RateLimit int `gorm:"default:60;not null" json:"rate_limit"`
// Status 密钥状态
Status enum.Status `gorm:"default:1;not null" json:"status"`
// ExpiredAt 过期时间(NULL=永不过期)
ExpiredAt *time.Time `json:"expired_at"`
}
+25
View File
@@ -0,0 +1,25 @@
package model
import (
"synoth.com/janus/internal/core"
"synoth.com/janus/internal/enum"
)
// Channel 路由转发通道
type Channel struct {
core.BaseModel
// Name 通道名称
Name string `gorm:"size:100;not null" json:"name"`
// ProviderID 供应商ID
ProviderID int64 `gorm:"not null" json:"provider_id"`
// ModelID 模型IDNULL表示供应商级别通道)
ModelID *int64 `json:"model_id"`
// Weight 负载均衡权重
Weight int `gorm:"default:1;not null" json:"weight"`
// Priority 优先级(数字越小越高)
Priority int `gorm:"default:1;not null" json:"priority"`
// RateLimit 每分钟请求数上限
RateLimit int `gorm:"default:60;not null" json:"rate_limit"`
// Status 通道状态
Status enum.Status `gorm:"default:1;not null" json:"status"`
}
+29
View File
@@ -0,0 +1,29 @@
package model
import (
"synoth.com/janus/internal/core"
"synoth.com/janus/internal/enum"
)
// Type 模型类型
type Type string
// JanusModel 供应商下可用的AI模型
type JanusModel struct {
core.BaseModel
// ProviderID 供应商ID
ProviderID int64 `gorm:"not null" json:"provider_id"`
// Name 模型名称
Name string `gorm:"not null" json:"name"`
// 模型类型
ModelType Type `gorm:"not null" json:"model_type"`
// 模型状态
Status enum.Status `gorm:"default:1;not null" json:"status"`
}
const (
Chat Type = "chat"
Completion Type = "completion"
Embedding Type = "embedding"
Image Type = "image"
)
+17
View File
@@ -0,0 +1,17 @@
package model
import (
"synoth.com/janus/internal/core"
"synoth.com/janus/internal/enum"
)
// JanusProvider 服务提供商
type JanusProvider struct {
core.BaseModel
// Name 服务供应商名称
Name string `gorm:"uniqueIndex;size:100;not null" json:"name"`
// BaseURL 服务地址
BaseURL string `gorm:"size:255;not null" json:"base_url"`
// Status 服务状态(1=启用,0=停用)
Status enum.Status `gorm:"default:1;not null" json:"status"`
}