Search code examples
gotoml

How to define a map in 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


Solution

  • 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" }]