Skip to content
Discussion options

You must be logged in to vote

Okay I figured it out. You need to wrap it all in another struct, as follows:

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/pelletier/go-toml/v2"
)

type Config struct {
	Values Values "values"
}

type Values struct {
    Value1 int
    Value2 string
    Value3 float64
}

func main() {
    var cfg Config

    data, err := os.ReadFile("test.toml")
    if err != nil {
        log.Fatal(err)
    }

    err = toml.Unmarshal(data, &cfg)
    if err != nil {
        panic(err)
    }

    fmt.Println(cfg.Values.Value1)
    fmt.Println(cfg.Values.Value2)
    fmt.Println(cfg.Values.Value3)
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by bogdan-the-great
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant