shconf

package
v0.0.0-...-d459dd1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package shconf implements a parser and scanner for the configuration in format shell-variable.

The configuration file consists on entries with the format "key" [separator] "value". The comments are indicated by "#" at the beginning of a line and upon the keys.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKey       = errors.New("key not found")
	ErrStructPtr = errors.New("argument must be a pointer to struct")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

A Config represents the configuration.

func ParseFile

func ParseFile(name string) (*Config, error)

ParseFile creates a new Config and parses the file configuration from the named file.

func (*Config) Get

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

Get returns the string value for a given key.

func (*Config) Getbool

func (c *Config) Getbool(key string) (bool, error)

Getbool returns the boolean value for a given key.

func (*Config) Getfloat

func (c *Config) Getfloat(key string) (float64, error)

Getfloat returns the float value for a given key.

func (*Config) Getint

func (c *Config) Getint(key string) (int, error)

Getint returns the integer value for a given key.

func (*Config) Getuint

func (c *Config) Getuint(key string) (uint, error)

Getuint returns the unsigned integer value for a given key.

func (*Config) Print

func (c *Config) Print()

Print outputs the keys and values parsed.

func (*Config) Separator

func (c *Config) Separator() []byte

Separator returns the character/s used to separate the key from the value.

func (*Config) Set

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

Set writes a new value for key.

func (*Config) Unmarshal

func (c *Config) Unmarshal(out interface{}) error

Unmarshal assigns values into the pointer to struct given by out, for the keys found.

The valid types in the struct fields for the matched keys are: bool, int, uint, float64, string.

The errors that Unmarshal return can be ErrStructPtr or TypeError.

type Option

type Option uint8

option represents the option to run the scanner.

const (
	SKIP_KEYS_DISABLED Option = iota + 1
	GET_KEYS_DISABLED
)

type Scanner

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

Scanner provides a convenient interface for reading data such as a file of lines of text in format key-value. Successive calls to the Scan method will step through the 'tokens' of a file, skipping the bytes between the tokens.

Scanning stops unrecoverably at EOF, the first I/O error, or a token too large to fit in the buffer.

func NewScanner

func NewScanner(r io.Reader) *Scanner

NewScanner returns a new Scanner to read from r, with the option to skip the keys disabled.

func (*Scanner) Bytes

func (s *Scanner) Bytes() (key, value []byte)

Bytes returns the most recents tokens generated by a call to Scan. The underlying array may point to data that will be overwritten by a subsequent call to Scan. It does no allocation.

func (*Scanner) Err

func (s *Scanner) Err() error

Err returns the first non-EOF error that was encountered by the Scanner.

func (*Scanner) Scan

func (s *Scanner) Scan() bool

Scan advances the Scanner to the next tokens, which will then be available through the Bytes or Text method. It returns false when the scan stops, either by reaching the end of the input or an error. After Scan returns false, the Err method will return any error that occurred during scanning, except that if it was io.EOF, Err will return nil.

func (*Scanner) Separator

func (s *Scanner) Separator() []byte

Separator returns the character/s used to separate the key from the value.

The separator is got in the first call to "Scan()"; if it has not been called, this makes it explicitly but panics when there is any error.

func (*Scanner) Text

func (s *Scanner) Text() (key, value string)

Text returns the most recents tokens generated by a call to Scan as a newly allocated string holding its bytes.

type TypeError

type TypeError string

A TypeError represents the type no supported in function Unmarshal.

func (TypeError) Error

func (e TypeError) Error() string

Jump to

Keyboard shortcuts

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