package shconf
import "github.com/tredoe/osutil/config/shconf"
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 ¶
- Variables
- type Config
- func ParseFile(name string) (*Config, error)
- func (c *Config) Get(key string) (string, error)
- func (c *Config) Getbool(key string) (bool, error)
- func (c *Config) Getfloat(key string) (float64, error)
- func (c *Config) Getint(key string) (int, error)
- func (c *Config) Getuint(key string) (uint, error)
- func (c *Config) Print()
- func (c *Config) Separator() []byte
- func (c *Config) Set(key, value string) error
- func (c *Config) Unmarshal(out interface{}) error
- type Scanner
- func NewScanner(r io.Reader) *Scanner
- func (s *Scanner) Bytes() (key, value []byte)
- func (s *Scanner) Err() error
- func (s *Scanner) Scan() bool
- func (s *Scanner) Separator() []byte
- func (s *Scanner) Text() (key, value string)
- type TypeError
Variables ¶
var ( ErrKey = errors.New("key not found") ErrStructPtr = errors.New("argument must be a pointer to struct") )
Types ¶
type Config ¶
A Config represents the configuration.
func ParseFile ¶
ParseFile creates a new Config and parses the file configuration from the named file.
func (*Config) Get ¶
Get returns the string value for a given key.
func (*Config) Getbool ¶
Getbool returns the boolean value for a given key.
func (*Config) Getfloat ¶
Getfloat returns the float value for a given key.
func (*Config) Getint ¶
Getint returns the integer value for a given key.
func (*Config) Getuint ¶
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 ¶
Separator returns the character/s used to separate the key from the value.
func (*Config) Set ¶
Set writes a new value for key.
func (*Config) Unmarshal ¶
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 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.
The valid characters for the keys are: [a-zA-Z_.]
Scanning stops unrecoverably at EOF, the first I/O error, or a token too large to fit in the buffer.
func NewScanner ¶
NewScanner returns a new Scanner to read from r, with the option to skip the keys disabled.
func (*Scanner) Bytes ¶
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 ¶
Err returns the first non-EOF error that was encountered by the Scanner.
func (*Scanner) Scan ¶
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 ¶
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 ¶
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 ¶
Source Files ¶
- Version
- v1.5.0 (latest)
- Published
- Jun 4, 2024
- Platform
- linux/amd64
- Imports
- 12 packages
- Last checked
- 1 day ago –
Tools for package owners.