ini

package
v0.0.0-...-3efd6c7 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2018 License: BSD-3-Clause, MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Example

Example is a basic example for the usage of the ini source.

package main

import (
	"fmt"

	"gitlab.com/silentteacup/congo"
)

// content is the content of a ini-file used in
// this example
const content = "" +
	"# Comment\n" +
	"; Number\n" +
	"number=54\n" +
	"; Decimal\n" +
	"decimal=0.5\n" +
	"[section]\n" +
	"duration=2h45m"

// Example is a basic example for the usage of the ini source.
func main() {
	// Get ini source
	bytes := []byte(content)
	src := FromBytes(bytes)

	// main configuration
	cfg := congo.New("main", src)

	debug := cfg.Bool("debug", false, "Can be used to enable debug mode.")
	number := cfg.Int("number", 0, "Set a number")
	decimal := cfg.Float64("decimal", 0.2, "Set a decimal")

	// section of configuration
	subCfg := congo.New("section", src.Section("section"))
	duration := subCfg.Duration("duration", 0, "Set the duration.")

	// Load configurations
	cfg.Init()
	cfg.Load()
	subCfg.Init()
	subCfg.Load()

	if *debug {
		fmt.Println("Debug enabled!")
	}
	fmt.Printf("Using number %d and decimal %f\n", *number, *decimal)

	fmt.Printf("%v", *duration)
}
Output:

Using number 54 and decimal 0.500000
2h45m0s

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Source

type Source interface {
	congo.Source
	Section(name string) Source
	WriteDefaults(w io.Writer) error
	SetLooseLoad(loose bool) Source
}

Source a ini source uses input in ini-syntax to load settings.

func FromBytes

func FromBytes(content []byte) Source

FromBytes creates a new ini source directly from the data that should be read.

func FromFile

func FromFile(path string) Source

FromFile creates a new ini source which uses the file at given path to load the configuration.

func New

func New(reader io.ReadCloser) Source

New creates a new ini source which reads from given reader.

Jump to

Keyboard shortcuts

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