Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a map in TOML?

Tags:

go

toml

How to define a map in TOML?

For example, I want to define something like:

[FOO]

Usernames_Passwords='{"user1":"pass1","user2":"pass2"}'

and then in go convert them to a map[string]string

like image 403
Said Saifi Avatar asked Dec 20 '16 12:12

Said Saifi


People also ask

How do TOML files work?

TOML is a file format for configuration files. It is intended to be easy to read and write due to obvious semantics which aim to be "minimal", and is designed to map unambiguously to a dictionary. Its specification is open-source, and receives community contributions.

What is a TOML table?

TOML stands for Tom's Obvious, Minimal Language. It is a data serialisation language designed to be a minimal configuration file format that's easy to read due to obvious semantics.

Is TOML whitespace sensitive?

TOML is case-sensitive. A TOML file must be a valid UTF-8 encoded Unicode document. Whitespace means tab (0x09) or space (0x20).

What is TOML extension?

A TOML file is a configuration file saved in the open source TOML (Tom's Obvious, Minimal Language) file format. It is used to configure the parameters and settings of various software projects. TOML files contain configuration information in key-value pairs and are meant to be more readable than .


1 Answers

You can have maps like this:

name = { first = "Tom", last = "Preston-Werner" }
point = { x = 1, y = 2 }

See: https://github.com/toml-lang/toml#user-content-inline-table

In your case, it looks like you want a password table, or an array of maps. You can make it like this:

[[user_entry]]
name = "user1"
pass = "pass1"

[[user_entry]]
name = "user2"
pass = "pass2"

Or more concisely:

user_entry = [{ name = "user1", pass = "pass1" },
              { name = "user2", pass = "pass2" }]
like image 93
Shou Ya Avatar answered Oct 22 '22 17:10

Shou Ya