strongParser

package
v1.1.33 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BoolMapping = map[string]bool{
	"1":        true,
	"true":     true,
	"on":       true,
	"yes":      true,
	"y":        true,
	"enable":   true,
	"enabled":  true,
	"0":        false,
	"false":    false,
	"off":      false,
	"no":       false,
	"n":        false,
	"disable":  false,
	"disabled": false,
}

BoolMapping is a map of strings to bool. WARNING: This is not a safe map, it should remain read-only.

View Source
var (
	DefaultMainSection = "main"
)

Functions

func GetDefaultValue

func GetDefaultValue(kind reflect.Kind) any

func GetPointerKind

func GetPointerKind(t reflect.Type) reflect.Kind

func ParseByteConfig

func ParseByteConfig(value any, b []byte) error

func ParseConfig

func ParseConfig(value any, filename string) error

func ParseConfigWithOption

func ParseConfigWithOption(value any, filename string, opt *ConfigParserOptions) error

func ParseStringConfig

func ParseStringConfig(value any, strValue string) error

func ParseStringConfigWithOption

func ParseStringConfigWithOption(value any, strValue string, opt *ConfigParserOptions) error

func SetDefaultValue

func SetDefaultValue(field reflect.Value, kind reflect.Kind)

Types

type ChainMap

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

func NewChainMap

func NewChainMap(dicts ...Dict) *ChainMap

func (*ChainMap) Get

func (c *ChainMap) Get(key string) string

func (*ChainMap) Len

func (c *ChainMap) Len() int

type Config

type Config map[string]*Section

Config represents a Python style configuration file.

type ConfigParser

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

ConfigParser ties together a Config and default values for use in interpolated configuration values.

func NewConfigParser

func NewConfigParser() *ConfigParser

New creates a new ConfigParser.

func NewConfigParserFromFile

func NewConfigParserFromFile(filename string) (*ConfigParser, error)

NewConfigParserFromFile creates a new ConfigParser struct populated from the supplied filename.

func NewWithDefaults

func NewWithDefaults(defaults Dict) *ConfigParser

NewWithDefaults allows creation of a new ConfigParser with a pre-existing Dict.

func Parse

func Parse(filename string) (*ConfigParser, error)

Parse takes a filename and parses it into a ConfigParser value.

func ParseBytes

func ParseBytes(b []byte) (*ConfigParser, error)

ParseBytes takes bytes array and parses it into a ConfigParser value.

func ParseString

func ParseString(value string) (*ConfigParser, error)

ParseBytes takes bytes array and parses it into a ConfigParser value.

func (*ConfigParser) Defaults

func (p *ConfigParser) Defaults() Dict

Defaults returns the items in the map used for default values.

func (*ConfigParser) Get

func (p *ConfigParser) Get(section, option string) (string, error)

Get returns string value for the named option.

Returns an error if a section does not exist Returns an error if the option does not exist either in the section or in the defaults

func (*ConfigParser) GetBool

func (p *ConfigParser) GetBool(section, option string) (bool, error)

func (*ConfigParser) GetComplex128

func (p *ConfigParser) GetComplex128(section, option string) (complex128, error)

func (*ConfigParser) GetFloat64

func (p *ConfigParser) GetFloat64(section, option string) (float64, error)

func (*ConfigParser) GetInt64

func (p *ConfigParser) GetInt64(section, option string) (int64, error)

func (*ConfigParser) GetIntByType

func (p *ConfigParser) GetIntByType(section, option, fType string) (int64, error)

func (*ConfigParser) GetIntSlice

func (p *ConfigParser) GetIntSlice(section, option string) ([]int64, error)

func (*ConfigParser) GetRune

func (p *ConfigParser) GetRune(section, option string) rune

func (*ConfigParser) GetStringSlice

func (p *ConfigParser) GetStringSlice(section, option string) ([]string, error)

func (*ConfigParser) GetUint64

func (p *ConfigParser) GetUint64(section, option string) (uint64, error)

func (*ConfigParser) HasOption

func (p *ConfigParser) HasOption(section, option string) (bool, error)

func (*ConfigParser) HasSection

func (p *ConfigParser) HasSection(section string) bool

HasSection returns true if the named section is present in the configuration.

The DEFAULT section is not acknowledged.

func (*ConfigParser) Items

func (p *ConfigParser) Items(section string) (Dict, error)

Items returns a copy of the section Dict not including the Defaults.

NOTE: This is different from the Python version which returns a list of tuples

func (*ConfigParser) ItemsWithDefaults

func (p *ConfigParser) ItemsWithDefaults(section string) (Dict, error)

ItemsWithDefaults returns a copy of the named section Dict including any values from the Defaults.

NOTE: This is different from the Python version which returns a list of tuples

func (*ConfigParser) Options

func (p *ConfigParser) Options(section string) ([]string, error)

Options returns a list of option names for the given section name.

Returns an error if the section does not exist.

func (*ConfigParser) RemoveOption

func (p *ConfigParser) RemoveOption(section, option string) error

func (*ConfigParser) Sections

func (p *ConfigParser) Sections() []string

Sections returns a list of section names, excluding [DEFAULT].

func (*ConfigParser) Set

func (p *ConfigParser) Set(section, option, value string) error

Set puts the given option into the named section.

Returns an error if the section does not exist.

type ConfigParserOptions

type ConfigParserOptions struct {
	ReadEnv         bool
	MainSectionName string
}

type Dict

type Dict map[string]string

Dict is a simple string->string map.

func (Dict) Keys

func (d Dict) Keys() []string

Keys returns a sorted slice of keys

type InvalidParseError

type InvalidParseError struct {
	Type reflect.Type
}

InvalidParseError describes an invalid argument passed to ParseConfig. (The argument to ParseConfig must be a non-nil pointer.)

func (*InvalidParseError) Error

func (e *InvalidParseError) Error() string

type MainAndArrayContainer

type MainAndArrayContainer[mT any, mA any] struct {
	Main     *mT
	Sections []*mA
}

func ParseMainAndArrays

func ParseMainAndArrays[mT any, aT any](filename string, opt *ConfigParserOptions) (*MainAndArrayContainer[mT, aT], error)

func ParseMainAndArraysStr

func ParseMainAndArraysStr[mT any, aT any](valueStr string, opt *ConfigParserOptions) (*MainAndArrayContainer[mT, aT], error)

type Section

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

func (*Section) Add

func (s *Section) Add(key, value string) error

func (*Section) Get

func (s *Section) Get(key string) (string, error)

func (*Section) Items

func (s *Section) Items() Dict

func (*Section) Options

func (s *Section) Options() []string

func (*Section) Remove

func (s *Section) Remove(key string) error

type SectionValue

type SectionValue interface {
	SetSectionName(name string)
	GetSectionName() string
}

Jump to

Keyboard shortcuts

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