Version: 0.9.77.dev.260505
后端:
1.阶段 6 CP4/CP5 目录收口与共享边界纯化
- 将 backend 根目录收口为 services、client、gateway、cmd、shared 五个一级目录
- 收拢 bootstrap、inits、infra/kafka、infra/outbox、conv、respond、pkg、middleware,移除根目录旧实现与空目录
- 将 utils 下沉到 services/userauth/internal/auth,将 logic 下沉到 services/schedule/core/planning
- 将迁移期 runtime 桥接实现统一收拢到 services/runtime/{conv,dao,eventsvc,model},删除 shared/legacy 与未再被 import 的旧 service 实现
- 将 gateway/shared/respond 收口为 HTTP/Gin 错误写回适配,shared/respond 仅保留共享错误语义与状态映射
- 将 HTTP IdempotencyMiddleware 与 RateLimitMiddleware 收口到 gateway/middleware
- 将 GormCachePlugin 下沉到 shared/infra/gormcache,将共享 RateLimiter 下沉到 shared/infra/ratelimit,将 agent token budget 下沉到 services/agent/shared
- 删除 InitEino 兼容壳,收缩 cmd/internal/coreinit 仅保留旧组合壳残留域初始化语义
- 更新微服务迁移计划与桌面 checklist,补齐 CP4/CP5 当前切流点、目录终态与验证结果
- 完成 go test ./...、git diff --check 与最终真实 smoke;health、register/login、task/create+get、schedule/today、task-class/list、memory/items、agent chat/meta/timeline/context-stats 全部 200,SSE 合并结果为 CP5_OK 且 [DONE] 只有 1 个
This commit is contained in:
64
backend/shared/infra/outbox/event_contract.go
Normal file
64
backend/shared/infra/outbox/event_contract.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package outbox
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultEventVersion 是通用事件协议默认版本。
|
||||
DefaultEventVersion = "v1"
|
||||
)
|
||||
|
||||
// OutboxEventPayload 是 outbox.payload 的统一事件外壳。
|
||||
type OutboxEventPayload struct {
|
||||
EventID string `json:"event_id,omitempty"`
|
||||
EventType string `json:"event_type"`
|
||||
EventVersion string `json:"event_version,omitempty"`
|
||||
AggregateID string `json:"aggregate_id,omitempty"`
|
||||
Payload json.RawMessage `json:"payload"`
|
||||
}
|
||||
|
||||
// ParsedOutboxEventPayload 是 dispatch 阶段使用的标准化结构。
|
||||
type ParsedOutboxEventPayload struct {
|
||||
EventID string
|
||||
EventType string
|
||||
EventVersion string
|
||||
AggregateID string
|
||||
PayloadJSON json.RawMessage
|
||||
}
|
||||
|
||||
// parseOutboxEventPayload 解析 outbox.payload。
|
||||
//
|
||||
// 当前策略(极致清理版):
|
||||
// 1. 只接受“统一事件外壳”格式;
|
||||
// 2. 不再支持旧格式纯业务 JSON 回退;
|
||||
// 3. event_type 缺失时直接报错,交由上层标 dead。
|
||||
func parseOutboxEventPayload(rawPayload string) (*ParsedOutboxEventPayload, error) {
|
||||
var wrapped OutboxEventPayload
|
||||
if err := json.Unmarshal([]byte(rawPayload), &wrapped); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
eventType := strings.TrimSpace(wrapped.EventType)
|
||||
if eventType == "" {
|
||||
return nil, errors.New("event type is empty")
|
||||
}
|
||||
if len(wrapped.Payload) == 0 {
|
||||
return nil, errors.New("payload is empty")
|
||||
}
|
||||
|
||||
eventVersion := strings.TrimSpace(wrapped.EventVersion)
|
||||
if eventVersion == "" {
|
||||
eventVersion = DefaultEventVersion
|
||||
}
|
||||
|
||||
return &ParsedOutboxEventPayload{
|
||||
EventID: strings.TrimSpace(wrapped.EventID),
|
||||
EventType: eventType,
|
||||
EventVersion: eventVersion,
|
||||
AggregateID: strings.TrimSpace(wrapped.AggregateID),
|
||||
PayloadJSON: wrapped.Payload,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user