背景
在一些特定的业务场景(审计日志)下,往往会需要在 model 层 (不管是 M1 -> M 还是 P2 ->(C3) -> M ) 记录一些 changelog(auditlog) 变化
Proposal
The Generator (diff模板生成)
在 (YAML)model struct 上生成 diff 方法,diff 方法接受另一个 M (提供 option , 可以带入一个 P -> C -> M 的转换过程)。
// 方法摘要
func (m *Model) Diff(m1 *Model) (bool,Differ,error)
The Differ
Differ 用来描述一次具体的DIFF结果,DIFF 结果可以按照不同业务场景组装:
- Extras: 提供额外信息展示
- OnKey: 用来描述oplog是否需要在
Key 的层级聚合
type Differ struct{
// not export field , export behavior as method
before *M
// not export field , export behavior as method
after *M
}