咱們知道如今主流的配置文件格式有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