1 | import toml |
2 | import toml.to |
3 | |
4 | // Complete text from the example in the README.md: |
5 | // https://github.com/toml-lang/toml/blob/3b11f6921da7b6f5db37af039aa021fee450c091/README.md#Example |
6 | const toml_text = '# This is a TOML document. |
7 | |
8 | title = "TOML Example" |
9 | |
10 | [owner] |
11 | name = "Tom Preston-Werner" |
12 | dob = 1979-05-27T07:32:00-08:00 # First class dates |
13 | |
14 | [database] |
15 | server = "192.168.1.1" |
16 | ports = [ 8000, 8001, 8002 ] |
17 | connection_max = 5000 |
18 | enabled = true |
19 | |
20 | [servers] |
21 | |
22 | # Indentation (tabs and/or spaces) is allowed but not required |
23 | [servers.alpha] |
24 | ip = "10.0.0.1" |
25 | dc = "eqdc10" |
26 | |
27 | [servers.beta] |
28 | ip = "10.0.0.2" |
29 | dc = "eqdc10" |
30 | |
31 | [clients] |
32 | data = [ ["gamma", "delta"], [1, 2] ] |
33 | |
34 | # Line breaks are OK when inside arrays |
35 | hosts = [ |
36 | "alpha", |
37 | "omega" |
38 | ]' |
39 | |
40 | fn main() { |
41 | doc := toml.parse_text(toml_text) or { panic(err) } |
42 | title := doc.value('title').string() |
43 | println('title: "${title}"') |
44 | ip := doc.value('servers.alpha.ip').string() |
45 | println('Server IP: "${ip}"') |
46 | |
47 | toml_json := to.json(doc) |
48 | println(toml_json) |
49 | } |