ini

package module
v0.0.0-...-e7cd825 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2015 License: MIT Imports: 6 Imported by: 3

README

ini

Yet another .INI file parser / writer. Created because the existing ones were either not general enough (allowing easy access to all parts of the original file) or made annoying assumptions about the format. And probably equal parts NIH. You might want to just write your own instead of using this one, you know that's where you'll end up in the end anyhow.

Documentation

http://godoc.org/github.com/calmh/ini

Example

fd, _ := os.Open("foo.ini")
cfg := ini.Parse(fd)
fd.Close()

val := cfg.Get("general", "foo")
cfg.Set("general", "bar", "baz")

fd, _ = os.Create("bar.ini")
err := cfg.Write(fd)
if err != nil {
	// ...
}
err = fd.Close()

License

MIT

Documentation

Overview

Package ini provides trivial parsing of .INI format files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config is a parsed INI format file.

func Parse

func Parse(stream io.Reader) Config

Parse reads the given io.Reader and returns a parsed Config object.

func (*Config) AddComment

func (c *Config) AddComment(sect, comment string)

AddComments appends the comment to the list of comments for the section.

func (*Config) Comments

func (c *Config) Comments(section string) []string

Comments returns the list of comments in a given section. For the empty string, returns the file comments.

func (*Config) Delete

func (c *Config) Delete(section, key string)

Delete removes the option from the specified section.

func (*Config) Get

func (c *Config) Get(section, key string) string

Get gets the value from the specified section and key name, or the empty string if either the section or the key is missing.

func (*Config) OptionMap

func (c *Config) OptionMap(section string) map[string]string

OptionMap returns the map option => value for a given section.

func (*Config) Options

func (c *Config) Options(section string) []string

Options returns the list of options in a given section.

func (*Config) Sections

func (c *Config) Sections() []string

Sections returns the list of sections in the file.

func (*Config) Set

func (c *Config) Set(sectionName, key, value string)

Set sets a value for an option in a section. If the option exists, it's value will be overwritten. If the option does not exist, it will be added. If the section does not exist, it will be added and the option added to it.

func (*Config) Write

func (c *Config) Write(out io.Writer) error

Write writes the sections and options to the io.Writer in INI format.

Jump to

Keyboard shortcuts

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