Get the App
SLTechnology News&Howtos  ›  Servers  › 

Verify the validity of the toml profile

Shulou Source: shulou.com Published: 2022-06-02 11:56:30 10月04日 Update

Background

We know that the mainstream configuration file format is xml,json,toml,yaml, and here I'll take toml as an example, because our project uses a configuration file in toml format. Once, when the code was released online, the validity of the toml configuration file was not verified. After the configuration was pushed up, the program did not start properly, resulting in the service being unavailable.

Thinking

After this error, I think we should be able to verify the validity of the configuration file in advance before releasing the code, so as to avoid low-level human error.

Push the wrong configuration file online, so you want to find a tool that can verify the validity of the toml profile.

In the solution, golang needs to be installed here, assuming that in the linux environment

Get the source code

Go get github.com/BurntSushi/toml

Go to the directory github.com/BurntSushi/tomlcmd/tomlv and compile

Go build.

Then put tomlv in the / bin directory. Verify the validity of the toml configuration file, using the following:

Tomlv some-toml-file.toml

If the error will have output, such as

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

We can then judge whether the verification is successful or not based on the return status of the command, 0 successful and 1 failed.

Also view the various types of configuration items for toml:

Tomlv-types some-toml-file.toml

The results are as follows:

Tags: Configuration file validation legal legal success code format directory low-level mainstream command tool scheme time source code status environment program type Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB Apple Shulou Technology vpn