咱们知道如今主流的配置文件格式有xml,json,toml,yaml,这里我以toml为例,由于咱们项目用的是toml格式的配置文件。有一次线上发布代码的时候因为没有验证toml配置文件的合法性,配置推上去后,程序没有正常启动,致使服务不可用。linux
出现这个失误以后,我认为应该能够在发布代码以前,先提早验证下配置文件的合法性,避免出现低级的人为失误,
把错误的配置文件推到线上去,因而想找能够验证toml配置文件的合法性的工具。git
这里须要安装golang,假设在linux环境下
获取源码github
go get github.com/BurntSushi/tomlgolang
go build .json
tomlv some-toml-file.tomlide
若是错误会有输出,好比工具
Error in 'config.conf': Near line 1 (last key parsed 'service'): expected a top-level item to end with a newline, comment, or EOF, but got ']' instead
而后咱们能够根据这个命令的返回状态来判断是否验证成功,0 成功 ,1 失败。ui
tomlv -types some-toml-file.tomlcode
结果以下:xml