-
I have two variables which have same type The Address is very long so I want to display it in different lines, and the Name is short and it's ok to display in one line. The code: package main
import (
"bytes"
"fmt"
"github.com/pelletier/go-toml/v2"
)
type Config struct {
Address map[string][]string `toml:",multiline"` // grouped by country
Name map[string][]string // grouped by age
}
func main() {
cfg := &Config{}
cfg.Address = map[string][]string{
"some country": {
"some very __________long________ address",
"some very __________long________ address",
"some very __________long________ address",
},
"some other country": {
"some very __________long________ address",
"some very __________long________ address",
},
}
cfg.Name = map[string][]string{
"20-30": {
"name a", "name b", "name c" .. lots of names,
},
}
buf := bytes.Buffer{}
enc := toml.NewEncoder(&buf)
enc.SetIndentTables(true)
enc.Encode(cfg)
fmt.Println(buf.String())
} I found there is Is it possible to show these arrays in different styles? Or maybe some feature like Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Sorry for the late reply! I think your intuition is right: |
Beta Was this translation helpful? Give feedback.
-
I have this code. package main
import (
"log"
"os"
toml "github.com/pelletier/go-toml/v2"
)
type Foo struct {
Data map[string]string `toml:"data,multiline"`
}
func main() {
f := Foo{
Data: map[string]string{
"one": "hello\nworld",
},
}
enc := toml.NewEncoder(os.Stdout)
enc.SetArraysMultiline(true)
if err := enc.Encode(f); err != nil {
log.Fatalln(err)
}
} I expected this:
But, instead I got this:
I would also like for |
Beta Was this translation helpful? Give feedback.
Sorry for the late reply! I think your intuition is right:
toml:",multiline"
should probably always push down themultiline
tag to the value instead of keeping it on the map, for which it makes no sense.