Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decoding table arrays need to be handled better #49

Closed
BurntSushi opened this issue Jun 27, 2014 · 2 comments
Closed

decoding table arrays need to be handled better #49

BurntSushi opened this issue Jun 27, 2014 · 2 comments

Comments

@BurntSushi
Copy link
Owner

The following produces a runtime error:

package main

import (
    "fmt"
    "log"

    "github.com/BurntSushi/toml"
)

type Server struct {
    Url  string
    Port int
}

type Host struct {
    Servers []Server
}

var blob = `
[Host]
[[Servers]]
Url = "http://burntsushi.net"
Port = 8080

[[Servers]]
Url = "http://github.com"
Port = 1234
`

func main() {
    config := Host{
        Servers: []Server{
            {
                Url:  "http://google.com",
                Port: 80,
            },
        },
    }
    if _, err := toml.Decode(blob, &config); err != nil {
        log.Fatal(err)
    }
    fmt.Printf("%#v\n", config)
}

This is because (I think) the default value. The decoder is probably checking if it's not nil, and then just assuming that it is the right size. It should be smarter. (Just appending isn't quite right either, because I think it should overwrite the default value. But I should probably check the behavior of the standard library decoders before implementing that.)

@porjo
Copy link

porjo commented Dec 30, 2014

+1

Is it possible to use a slice of structs currently? (If so, how?) I'm getting panic: reflect: slice index out of range error when I try...

@cespare
Copy link
Collaborator

cespare commented Feb 23, 2016

Fixed by #84.

@cespare cespare closed this as completed Feb 23, 2016
ebrady pushed a commit to dvln/toml that referenced this issue Oct 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants