htoml4g

module
v0.9.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2024 License: Apache-2.0

README

htoml4g

hooto toml-based configuration library for golang.

Example:

package main

import (
	"fmt"

	"github.com/hooto/htoml4g/htoml"
)

type ConfigEntry struct {
	Title     string           `toml:"title"`
	Databases []ConfigDatabase `toml:"databases"`
}

type ConfigDatabase struct {
	Addr    string `toml:"addr"`
	ConnMax int    `toml:"conn_max"`
}

var (
	confRaw = []byte(`
# comment of example
title = "TOML Example"

[[databases]]
addr = "192.168.0.1:3001"
conn_max = 100

[[databases]]
addr = "192.168.0.2:3001"
conn_max = 100
`)
)

func main() {

	var item ConfigEntry
	if err := htoml.Decode(confRaw, &item); err != nil {
		panic(err)
	}

	fmt.Printf("title : %s\n", item.Title)
	fmt.Printf("databases %d :\n", len(item.Databases))
	for i, v := range item.Databases {
		fmt.Printf("  database #%d, addr %s, conn_max %d\n",
			i, v.Addr, v.ConnMax)
	}
}

Dependent Projects or Documents

Directories

Path Synopsis
cmd
internal
toml
Package toml implements decoding and encoding of TOML files.
Package toml implements decoding and encoding of TOML files.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL