You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I expected to be able to decode a table into a map from string to a type of my choosing, as long as I provided an unmarshaling function for that type (like the duration example). But it doesn't seem to work.
Here's a program that I expect to panic during decoding:
package main
import (
"fmt"
"github.com/BurntSushi/toml"
)
type config struct {
Sites map[string]custom
}
type custom struct {
Value string
}
func main() {
var conf config
blob := `
[sites]
ebay = "https://ebay.com"
google = "https://google.com"
`
toml.Decode(blob, &conf)
fmt.Printf("% v\n", conf)
}
func (c *custom) UnmarshalText(text []byte) error {
panic("unmarshal")
}
But the UnmarshalText function is never called, and the result is just {map[]}
Am I doing something wrong, or is this not possible?
The text was updated successfully, but these errors were encountered:
I tried with the *custom value, but then the UnmarshalText function gets called with a nil pointer as the receiver (so replacing the panic with something "useful" doesn't actually work). This version panics:
package main
import (
"fmt"
"github.com/BurntSushi/toml"
)
type config struct {
Sites map[string]*custom
}
type custom struct {
Value string
}
func main() {
var conf config
blob := `
[sites]
ebay = "https://ebay.com"
google = "https://google.com"
`
toml.Decode(blob, &conf)
fmt.Printf("% v\n", conf)
}
func (c *custom) UnmarshalText(text []byte) error {
c.Value = string(text)
return nil
}
I expected to be able to decode a table into a map from string to a type of my choosing, as long as I provided an unmarshaling function for that type (like the duration example). But it doesn't seem to work.
Here's a program that I expect to panic during decoding:
But the UnmarshalText function is never called, and the result is just
{map[]}
Am I doing something wrong, or is this not possible?
The text was updated successfully, but these errors were encountered: