I’m trying to unmarshal Config
struct but failing to do so. Can someone please tell me why it’s not working?
go playground: https://go.dev/play/p/a8oHOLpm0em
package main
import (
"fmt"
"github.com/BurntSushi/toml"
)
type Meta struct {
config Config `toml:"config"`
Include []string `toml:"include"`
Exclude []string `toml:"exclude"`
}
type Config struct {
Title string `toml:"title"`
Include []string `toml:"include"`
Exclude []string `toml:"exclude"`
}
var expected_data = `
include = ["README.md", "LICENSE"]
exclude = ["tests", "docs", "examples", "notebooks"]
[config]
include = ["README.md", "LICENSE"]
exclude = ["tests", "docs", "examples", "notebooks"]
title = "pytorch-forecasting"
`
func main() {
modfile := Meta{}
_ = toml.Unmarshal([]byte(expected_data), &modfile)
fmt.Println("Top level Include: ", modfile.Include)
fmt.Println("Top level Exclude: ", modfile.Exclude)
fmt.Println("Include: ", modfile.config.Include)
fmt.Println("Exclude: ", modfile.config.Exclude)
fmt.Println("Title: ", modfile.config.Title)
}
New contributor
Asish Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.