ini

package
v0.0.0-...-f308040 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ini implements an opinionated ini parser that only implements what we exactly need for WireGuard configs - key/values MUST live under a section - empty section names are NOT allowed - comments are indicated with a #

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type INI

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

INI is the struct for a ini file

func Parse

func Parse(f string) INI

Parse returns the INI struct from a string `f`

func (*INI) AddSection

func (i *INI) AddSection(name string) error

AddSection adds a section with name `name` and returns an error if the section already exists

func (*INI) Empty

func (i *INI) Empty() bool

Empty returns true if there are no sections defined in the INI

func (*INI) Section

func (i *INI) Section(name string) (*Section, error)

Section gets a section from the ini file

func (*INI) String

func (i *INI) String() string

String returns the representation of the ini as a string

type OrderedKeys

type OrderedKeys []string

OrderedKeys is a slice of strings that is used for an ordered map

func (*OrderedKeys) Remove

func (ok *OrderedKeys) Remove(name string)

Remove removes a `name` from the OrderedKeys slice by finding the name It is a no-op if the key does not exist

type Section

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

Section represents a single section within an ini file It consists of multiple key and values

func (*Section) AddKeyValue

func (sec *Section) AddKeyValue(key string, value string) error

AddKeyValue adds a new key `key` with value `value` It returns an error if the key already exists

func (*Section) AddOrReplaceKeyValue

func (sec *Section) AddOrReplaceKeyValue(key string, value string)

AddOrReplaceKeyValue adds a key `key` with value `value` If the key already exists it modifies the value

func (*Section) KeyValue

func (sec *Section) KeyValue(key string) (string, error)

KeyValue gets a value for key `key` It returns an error if the key does not exist

func (*Section) RemoveKey

func (sec *Section) RemoveKey(key string) (string, error)

RemoveKey removes a key `key` from the section It returns an error if the key cannot be found

Jump to

Keyboard shortcuts

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