ini

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2022 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

ini

A simple INI file parser and builder.

What

Read INI files, or build them section by section. Datatypes are kept very simple.

The main fuctions are:

  • Load(): Load and parse into a structure.
  • Save(): Store an INI file.
  • New(): Create a new INI file.

How

Load an INI file:

	...
	f,err := ini.LoadFile("filename.ini")
	...

Add a section:

	...
	sec := f.AddSection("server")
	...

Add entries to the section:

	...
	sec.AddString("host", "localhost")
	sec.AddInt("port", 8080)
	sec.AddBool("ssl", false)
	sec.AddFloat("intensity", 10.0)
	...

Save the file:

	...
	f.SaveTo("filename.ini")
	...

Documentation

Index

Constants

View Source
const (
	// Bool type
	Bool = iota
	// Int type
	Int
	// INIFloat type
	Float
	// String type
	String
)

Variables

This section is empty.

Functions

This section is empty.

Types

type INI

type INI struct {
	// Sections with settings.
	Sections map[string]*INISection
	// Order sections were loaded or added in.
	Order []string
}

INI file base structure.

func Load

func Load(filename string) (*INI, error)

Load INI from file and take a guess at the types of each value.

func New

func New() *INI

New returns an empty INI structure.

func (*INI) AddSection

func (ini *INI) AddSection(name string) *INISection

AddSection to INI structure.

func (*INI) Save

func (ini *INI) Save(filename string, tabbed bool) error

Save outputs the INI to a file. If tabbed is true, the fields will be saved with a tab character prepended.

type INIField

type INIField struct {
	// Value will be stripped of surrounding whitespace when loaded.
	Value string
	// Type lets the user choose which Get* method to use when loading unknown files.
	Type byte
	// contains filtered or unexported fields
}

INIField contains a variable and its data.

func (*INIField) GetBool

func (f *INIField) GetBool(key string) bool

GetBool returns a field as a bool.

func (*INIField) GetFloat

func (f *INIField) GetFloat(key string) float64

GetFloat returns a field as a float64.

func (*INIField) GetInt

func (f *INIField) GetInt(key string) int64

GetInt returns a field as an int.

func (*INIField) SetBool

func (f *INIField) SetBool(key string, value bool)

SetBool sets a field to a bool.

func (*INIField) SetFloat

func (f *INIField) SetFloat(key string, value float64)

SetFloat sets a field to a float64.

func (*INIField) SetInt

func (f *INIField) SetInt(key string, value int64)

SetInt sets a field as an int.

func (*INIField) SetString

func (f *INIField) SetString(key, value string)

SetString sets a field as a string.

type INISection

type INISection struct {
	Fields map[string]*INIField
	// Order fields were loaded or added in.
	Order []string
}

INISection holds one or more fields.

func (*INISection) AddBool

func (s *INISection) AddBool(key string, value bool)

AddBool adds a new bool field to the section.

func (*INISection) AddFloat

func (s *INISection) AddFloat(key string, value float64)

AddFloat adds a new float64 field to the section.

func (*INISection) AddInt

func (s *INISection) AddInt(key string, value int64)

AddInt adds a new int64 field to the section.

func (*INISection) AddString

func (s *INISection) AddString(key string, value string)

AddString adds a new string field to the section.

func (*INISection) GetBool

func (s *INISection) GetBool(key string, alt bool) bool

GetBool returns a field as a bool, or the alternative.

func (*INISection) GetFloat

func (s *INISection) GetFloat(key string, alt float64) float64

GetFloat returns a field as a float64, or the alternative.

func (*INISection) GetInt

func (s *INISection) GetInt(key string, alt int64) int64

GetInt returns a field as an int64, or the alternative.

func (*INISection) GetString

func (s *INISection) GetString(key, alt string) string

GetString returns a field as a string, or the alternative.

Jump to

Keyboard shortcuts

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