A闪的 BLOG 技术与人文
在 博客系统设计总结(上) 一文中我介绍过博客系统的设计,在golang模块设计中一开始存在一些问题。三个系统之间相互有所关联,这也是一开始模块设计中的缺陷所在。

Blog Server 和 Blog Client 在编码模块上均与 Blog Admin Server 有所关联。例如,在数据库操作过程中,Blog Server有部分与Blog Admin Server存在公用模块,而提交数据,对数据进行验证时Blog Client 和 Blog Admin Server 存在公用模块。
在原有设计中三个服务之间的模块互相独立,不存在公用模块。这就导致每一次修改相关联代码时候,都需要修改两份。此次重构会将重复代码合并到 hackbloglib 公用库中。
博客客户端对于每次执行,都会按照如下流程执行:
command —-> config —-> merge —-> inspect —-> encode —-> acton
当每一次操作时,都会执行以上六步,如下面的每一次命令操作:

针对命令进行分析,将命令进行拆解
读取操作本地配置文件,将本地存储的操作记录还原到内存中。
这一步类似 setData 操作,将新的操作数据合并到旧的操作数据中。
对当前的操作数据进行 check 操作
编码
执行操作
对于不同的命令,每一步也会对命令进行过滤,如下表:
| command | network/local | args | run | encode | check |
|---|---|---|---|---|---|
| add | local | yes | no | no | no |
| rm | local | yes | no | no | no |
| commit | local | yes | no | no | no |
| push | network | no | yes | yes | yes |
| del | network | no | yes | yes | yes |
| get | network | no | yes | yes | yes |
| update | network | no | yes | yes | yes |
| help | local | no | yes | no | no |
| cat | network | no | yes | yes | no |
| arc | network | no | yes | yes | no |
| pag | network | no | yes | yes | no |
| opt | network | no | yes | yes | no |
| status | local | no | yes | no | no |
| clear | local | no | yes | no | no |
| cc | network | no | yes | yes | no |
| ck | local | no | yes | no | no |
通过以上表可以看出,针对不同命令对不同阶段的操作会有忽略对应执行函数。