ini

package module
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package ini implements parsing of the AWS shared config file.

Example:
sections, err := ini.OpenFile("/path/to/file")
if err != nil {
	panic(err)
}

profile := "foo"
section, ok := sections.GetSection(profile)
if !ok {
	fmt.Printf("section %q could not be found", profile)
}

Index

Constants

View Source
const (
	NoneType = ValueType(iota)
	StringType
	QuotedStringType
)

ValueType enums

Variables

This section is empty.

Functions

This section is empty.

Types

type Section

type Section struct {
	// Name is the Section profile name
	Name string

	// Errors is the list of errors
	Errors []error

	// Logs is the list of logs
	Logs []string

	// SourceFile is the INI Source file from where this section
	// was retrieved. They key is the property, value is the
	// source file the property was retrieved from.
	SourceFile map[string]string
	// contains filtered or unexported fields
}

Section contains a name and values. This represent a sectioned entry in a configuration file.

func NewSection

func NewSection(name string) Section

NewSection returns an initialize section for the name

func (Section) Bool

func (t Section) Bool(k string) (bool, bool)

Bool returns a bool value at k

func (Section) Float64

func (t Section) Float64(k string) (float64, bool)

Float64 returns a float value at k

func (Section) Has

func (t Section) Has(k string) bool

Has will return whether or not an entry exists in a given section

func (Section) Int

func (t Section) Int(k string) (int64, bool)

Int returns an integer value at k

func (Section) List added in v1.5.0

func (t Section) List() []string

List will return a list of all services in values

func (Section) Map added in v1.5.0

func (t Section) Map(k string) map[string]string

Map returns a map value at k

func (Section) String

func (t Section) String(k string) string

String returns the string value at k

func (Section) UpdateSourceFile

func (t Section) UpdateSourceFile(property string, filepath string)

UpdateSourceFile updates source file for a property to provided filepath.

func (Section) UpdateValue

func (t Section) UpdateValue(k string, v Value) error

UpdateValue updates value for a provided key with provided value

func (Section) ValueType

func (t Section) ValueType(k string) (ValueType, bool)

ValueType will returned what type the union is set to. If k was not found, the NoneType will be returned.

type Sections

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

Sections is a map of Section structures that represent a configuration.

func NewSections

func NewSections() Sections

NewSections returns empty ini Sections

func OpenFile

func OpenFile(path string) (sections Sections, err error)

OpenFile parses shared config from the given file path.

func Parse

func Parse(r io.Reader, path string) (Sections, error)

Parse parses shared config from the given reader.

func (Sections) DeleteSection

func (t Sections) DeleteSection(p string)

DeleteSection deletes a section entry/value for provided section name./

func (Sections) GetSection

func (t Sections) GetSection(p string) (Section, bool)

GetSection will return section p. If section p does not exist, false will be returned in the second parameter.

func (Sections) HasSection

func (t Sections) HasSection(p string) bool

HasSection denotes if Sections consist of a section with provided name.

func (Sections) List

func (t Sections) List() []string

List will return a list of all sections that were successfully parsed.

func (Sections) SetSection

func (t Sections) SetSection(p string, v Section) Sections

SetSection sets a section value for provided section name.

type UnableToReadFile

type UnableToReadFile struct {
	Err error
}

UnableToReadFile is an error indicating that a ini file could not be read

func (*UnableToReadFile) Error

func (e *UnableToReadFile) Error() string

Error returns an error message and the underlying error message if present

func (*UnableToReadFile) Unwrap

func (e *UnableToReadFile) Unwrap() error

Unwrap returns the underlying error

type Value

type Value struct {
	Type ValueType
	// contains filtered or unexported fields
}

Value is a union container

func NewStringValue

func NewStringValue(str string) (Value, error)

NewStringValue returns a Value type generated using a string input.

func (Value) BoolValue

func (v Value) BoolValue() (bool, bool)

BoolValue returns a bool value

func (Value) FloatValue

func (v Value) FloatValue() (float64, bool)

FloatValue returns a float value

func (Value) IntValue

func (v Value) IntValue() (int64, bool)

IntValue returns an integer value

func (Value) MapValue added in v1.5.0

func (v Value) MapValue() map[string]string

MapValue returns a map value for sub properties

func (Value) String

func (v Value) String() string

func (Value) StringValue

func (v Value) StringValue() string

StringValue returns the string value

type ValueType

type ValueType int

ValueType is an enum that will signify what type the Value is

func (ValueType) String

func (v ValueType) String() string

Jump to

Keyboard shortcuts

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