Some checks failed
CI / Build & Test (push) Failing after 40s
- kernel/plugin: 定义 Plugin 接口(Metadata/FxOption/SetupRoutes/Init) - kernel/plugin: 全局 Registry(Register/All/InitAll/Reset) - modules/example: 完整 4 层示例插件,实现 Plugin 接口 - config: 新增 PluginConfig(enabled 列表) - app.go: 集成插件系统 — fx.Invoke 注册 + plugin.All() 路由 + InitAll 生命周期
62 lines
1.8 KiB
Go
62 lines
1.8 KiB
Go
package domain
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"mengstack/internal/kernel/model"
|
|
)
|
|
|
|
// Example is a sample entity demonstrating the plugin data model.
|
|
type Example struct {
|
|
model.BaseModel
|
|
Name string `json:"name" gorm:"type:varchar(255);not null"`
|
|
Description string `json:"description" gorm:"type:text"`
|
|
Status int `json:"status" gorm:"type:smallint;default:1"`
|
|
ExpiresAt time.Time `json:"expires_at"`
|
|
}
|
|
|
|
func (Example) TableName() string { return "examples" }
|
|
|
|
// ExampleDTO is the response projection.
|
|
type ExampleDTO struct {
|
|
ID uint `json:"id"`
|
|
TenantID string `json:"tenant_id"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Status int `json:"status"`
|
|
ExpiresAt time.Time `json:"expires_at"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// ToDTO converts an Example entity to its DTO.
|
|
func ToDTO(e *Example) ExampleDTO {
|
|
return ExampleDTO{
|
|
ID: e.ID,
|
|
TenantID: e.TenantID,
|
|
Name: e.Name,
|
|
Description: e.Description,
|
|
Status: e.Status,
|
|
ExpiresAt: e.ExpiresAt,
|
|
CreatedAt: e.CreatedAt,
|
|
UpdatedAt: e.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
// CreateExampleRequest is the input for creating an example.
|
|
type CreateExampleRequest struct {
|
|
Name string `json:"name" binding:"required,max=255"`
|
|
Description string `json:"description"`
|
|
ExpiresAt time.Time `json:"expires_at"`
|
|
}
|
|
|
|
// Repository defines the data access contract for examples.
|
|
type Repository interface {
|
|
Create(ctx context.Context, e *Example) error
|
|
FindByID(ctx context.Context, tenantID string, id uint) (*Example, error)
|
|
FindAll(ctx context.Context, tenantID string) ([]Example, error)
|
|
Update(ctx context.Context, tenantID string, e *Example) error
|
|
Delete(ctx context.Context, tenantID string, id uint) error
|
|
}
|