inifile

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: MIT Imports: 5 Imported by: 0

README

go-inifile

Wrapper around gopkg.in/ini.v1 to make it look more like flag.String() etc.

Examples

  1. examples/simple/main.go
package main

import (
	"fmt"

	"github.com/sergereinov/go-inifile"
)

var (
	file        = inifile.New()
	dir         = file.String("Logs", "Dir", "./logs")
	maxFileSize = file.Int("Logs", "MaxFileSizeMB", 10)
	enable      = file.Bool("Logs", "Enable", true)
	tags        = file.Strings("Summary", "Tags", []string{"one", "five", "ten"})
	intervals   = file.Ints("Summary", "Intervals", []int{1, 5, 10})
)

func main() {
	fmt.Println("ini file is in", file.Path())
	fmt.Println("dir", dir)
	fmt.Println("maxFileSize", maxFileSize)
	fmt.Println("enable", enable)
	fmt.Println("tags", tags)
	fmt.Println("intervals", intervals)
}

Prints:

ini file is in D:\Progs\Go\go-inifile\simple.ini
dir ./logs
maxFileSize 10
enable true
tags [one five ten]
intervals [1 5 10]
  1. examples/named/main.go
package main

import (
	"fmt"

	"github.com/sergereinov/go-inifile"
)

func main() {
	// Create ini file accessor
	file := inifile.New("./custom.ini")

	// Read some values
	dir := file.String("Logs", "Dir", "./logs")
	tags := file.Strings("Summary", "Tags", []string{"one", "five", "ten"})

	// Save values back with defaults for missing keys
	file.Save()

	// Print results
	fmt.Println("ini file is in", file.Path())
	fmt.Println("dir", dir)
	fmt.Println("tags", tags)
}

It prints:

ini file is in D:\Progs\Go\go-inifile\custom.ini
dir ./logs
tags [one five ten]

And saves custom.ini:

[Logs]
Dir = ./logs

[Summary]
Tags = one, five, ten

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(optPath ...string) *iniFile

Simplified constructor

func NewIniFile

func NewIniFile(optPath ...string) (*iniFile, error)

Main constructor

Types

This section is empty.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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