Skip to content
/ mini Public

Parse (sort of) INI files like "flag" package in Go.

License

Notifications You must be signed in to change notification settings

lucasepe/mini

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mini

Parse (sort of) INI files like "flag" package in Go.

Example

import (
	"fmt"
	"log"
	"strings"

	"github.com/lucasepe/mini"
)

func ExampleNewConf() {
	data := `
width: 1600
subject: Computers,Education,Programming

[background]
art: shapes

[title]
text: Awesome Book!
color: #000000
font-size: 160
offset: 0.3
`
	conf := mini.NewConf()

	width := conf.Int("", "width", 1000)
	height := conf.Int("", "height", 1000)
	subject := conf.StringSlice("", "subject", []string{})
	watermark := conf.String("", "watermark", "")

	art := conf.Enum("background", "art", []string{
		"color-circles",
		"shapes",
		"circles-grid",
		"pixel-hole",
		"dots-wawe",
		"contour-line",
		"dot-line",
		"warp",
	})

	err := conf.Parse(strings.NewReader(data))
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(*width)
	fmt.Println(*height)
	fmt.Println(*subject)
	fmt.Println(*watermark)
	fmt.Println(*art)

	// Output:
	// 1600
	// 1000
	// [Computers,Education,Programming]
	//
	// shapes
}

About

Parse (sort of) INI files like "flag" package in Go.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages