txtparser

package
v0.0.0-...-6175eb3 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2017 License: GPL-2.0 Imports: 8 Imported by: 2

Documentation

Overview

Implement a universal parser for /etc/sysconfig files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sysconfig

type Sysconfig struct {
	AllValues []*SysconfigEntry // All key-value pairs in the orignal order.
	KeyValue  map[string]*SysconfigEntry
}

Key-value pairs of a sysconfig file. It is able to convert back to original text in the original key order.

func ParseSysconfig

func ParseSysconfig(input string) (*Sysconfig, error)

Read sysconfig text and parse the text into memory structures.

func ParseSysconfigFile

func ParseSysconfigFile(fileName string, autoCreate bool) (*Sysconfig, error)

Read sysconfig file and parse the file content into memory structures.

func (*Sysconfig) GetBool

func (conf *Sysconfig) GetBool(key string, defaultValue bool) bool

Return bool value that belongs to the key, or the default value if key does not exist. True values are "yes" or "true".

func (*Sysconfig) GetInt

func (conf *Sysconfig) GetInt(key string, defaultValue int) int

Return integer value that belongs to the key, or the default value if the key does not exist or value is not an integer.

func (*Sysconfig) GetIntArray

func (conf *Sysconfig) GetIntArray(key string, defaultValue []int) (ret []int)

Assume the key carries a space-separated array of integers, return the array. Discard malformed integers.

func (*Sysconfig) GetString

func (conf *Sysconfig) GetString(key, defaultValue string) string

Return string value that belongs to the key, or the default value if the key does not exist.

func (*Sysconfig) GetStringArray

func (conf *Sysconfig) GetStringArray(key string, defaultValue []string) (ret []string)

Assume the key carries a space-separated array value, return the value array.

func (*Sysconfig) GetUint64

func (conf *Sysconfig) GetUint64(key string, defaultValue uint64) uint64

Return uint64 value that belongs to the key, or the default value if the key does not exist or value is not an integer.

func (*Sysconfig) Set

func (conf *Sysconfig) Set(key string, value interface{})

Set value for a key. If the key does not yet exist, it is created.

func (*Sysconfig) SetIntArray

func (conf *Sysconfig) SetIntArray(key string, values []int)

Give a space-separated integer array value to a key. If the key does not yet exist, it is created.

func (*Sysconfig) SetStringArray

func (conf *Sysconfig) SetStringArray(key string, values []string)

Give a space-separated string array value to a key. If the key does not yet exist, it is created.

func (*Sysconfig) ToText

func (conf *Sysconfig) ToText() string

Convert key-value pairs back into text. Values are always surrounded by double-quotes.

type SysconfigEntry

type SysconfigEntry struct {
	LeadingComments []string // The comment lines leading to the key-value pair, including prefix '#', excluding end-of-line.
	Key             string   // The key.
	Value           string   // The value, excluding '=' character and double-quotes. Values will always come in double-quotes when converted to text.
}

A single key-value pair in sysconfig file.

Jump to

Keyboard shortcuts

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