0. 前提

1. 動作環境

  • CodePen

  • Steam

  • Gits

package main
import (
"fmt"
"github.com/BurntSushi/toml"
)
type API struct {
User string `toml:"user"`
Version string `toml:"version"`
Debug bool `toml:"debug"`
Limit uint `toml:"limit"`
}
func main() {
var config API
_, err := toml.DecodeFile("./config.toml", &config)
if err != nil {
fmt.Println(err)
}
fmt.Println(config.User)
fmt.Println(config.Version)
fmt.Println(config.Debug)
fmt.Println(config.Limit)
}
view raw toml1.go hosted with ❤ by GitHub
package main
import (
"fmt"
"github.com/BurntSushi/toml"
)
type Config struct {
API API
}
type API struct {
User string `toml:"user"`
Version string `toml:"version"`
Debug bool `toml:"debug"`
Limit uint `toml:"limit"`
}
func main() {
var config Config
_, err := toml.DecodeFile("./config.toml", &config)
if err != nil {
fmt.Println(err)
}
fmt.Println(config.API.User)
fmt.Println(config.API.Version)
fmt.Println(config.API.Debug)
fmt.Println(config.API.Limit)
}
view raw toml2.go hosted with ❤ by GitHub

. 最後に

. 参考にしたサイト