Skip to content

Draft: proposal: generator(all): Introduce the model struct diff mechanism , the ormDiffTag , and the generator #314

@scbizu

Description

@scbizu

背景

在一些特定的业务场景(审计日志)下,往往会需要在 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
}

Footnotes

  1. M: Model Struct

  2. P: (API)Protocol(ProtoBuffer/Thrift/Json-To-Go) Struct

  3. C: The Converter between P <-> M

Metadata

Metadata

Assignees

Labels

v2ezorm v2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions