|
H00gs |
at Nov 29, 2013 at 1:22 pm
|
⇧ |
| |
Hi Andrew, thanks for the code.
Ok, some code:
package main
import (
"fmt"
"<path to your toml pkg>"
)
//type A struct {
// Features map[string]string
//}
type A struct {
Features map[string]B
}
type B struct {
C string
}
func main() {
blob := `
[Bird]
[Bird.Features.color]
C = "white"
[Bird.Features.name]
C = "Polly"
[Dog]
[Dog.Features.color]
C = "black"
[Dog.Features.name]
C = "Fido"`
var a map[string]A
_, err := toml.Decode(blob, &a)
fmt.Printf("Toml decode produced error: %v\n", err)
fmt.Printf("Dog name = %v\n", a["Dog"].Features["name"].C)
}
So this works for me (with toml pkg location updated). But what if I want
to replace type B with a string value in the commented out version of type
A? How would the blob need to be formatted to eliminate B and its field C?
hoogs
On Friday, November 29, 2013 8:33:01 PM UTC+8, Andrew Gallant wrote:Author here. I'm not sure what you mean by anonymous fields for maps.
Could you give an example with with Go types? And perhaps also include the
TOML you think should go with it.
On Friday, November 29, 2013 1:33:47 AM UTC-5, h00gs wrote:Picked up
https://github.com/BurntSushi/toml and seems to work well
(thanks to the author).
But how to handle a map as field of primitives? e.g. with
type A struct {
Features map[string]string}
how would you format the toml file to ensure this could properly read in
a map such as {"key1": "val1", "key2": "val2"}? If instead we had
type A struct {
Features map[string]B}
type B struct {
C string
}
the toml doc:
[Bird]
[Bird.Features.color]
C = "white"
[Bird.Features.name]
C = "Polly"
[Dog]
[Dog.Features.color]
C = "black"
[Dog.Features.name]
C = "Fido"
seems like it works, but what about "anonymous" fields for maps? (or the
best workaround)
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.