config

package module
v0.0.0-...-ac6df9f Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 4 Imported by: 3

README

DEPRECATED

This utility is deprecated in favour of YAML based configuration files.

config

Simple file based configuration for go programs.

An example of the configuration file syntax is:

# Global keywords
keyword1=argument1,argument2
another=arg3
# Different sections can be added
[section1]
# This keyword is separate from the first one.
keyword1=different-arg
[section2]
my-keyword=my-argument

Different modules can retrieve the keywords related to selected sections.

TODO

  • Add smarter parsing for integers etc.
  • Add validation of keywords so that unknown keywords are flagged.

This is not an officially supported Google product.

Documentation

Index

Constants

View Source
const Global = "global"

Variables

This section is empty.

Functions

func SetDelimiters

func SetDelimiters(d string)

Types

type Conf

type Conf interface {
	Has(string) bool
	Get(string) []*Entry
	GetArg(string) (string, error)
}

Interface for accessing configuration tokens.

type Config

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

func ParseFile

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

func ParseFiles

func ParseFiles(optional bool, files []string) (*Config, error)

func ParseString

func ParseString(s string) (*Config, error)

func (*Config) Get

func (c *Config) Get(k string) []*Entry

func (*Config) GetArg

func (c *Config) GetArg(k string) (string, error)

func (*Config) GetSection

func (config *Config) GetSection(name string) *Section

Get the first section.

func (*Config) GetSections

func (config *Config) GetSections(name string) []*Section

func (*Config) Has

func (c *Config) Has(k string) bool

func (*Config) Merge

func (c *Config) Merge(c1 *Config)

func (*Config) Missing

func (c *Config) Missing(strs []string) []string

Return strings not present in config.

func (*Config) Parse

func (c *Config) Parse(k string, f string, a ...interface{}) (int, error)

func (*Config) ParseFile

func (c *Config) ParseFile(file string) error

type Entry

type Entry struct {
	Keyword  string
	Filename string
	Lineno   int
	Line     string
	Args     string // String following keyword
	Tokens   []string
}

Entry, one for each keyword.

type Section

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

The entries associated with a single section. The default section is named 'global'.

func (*Section) Get

func (s *Section) Get(k string) []*Entry

func (*Section) GetArg

func (s *Section) GetArg(k string) (string, error)

func (*Section) GetEntries

func (s *Section) GetEntries() []*Entry

func (*Section) Has

func (s *Section) Has(k string) bool

func (*Section) Parse

func (s *Section) Parse(k string, f string, a ...interface{}) (int, error)

Jump to

Keyboard shortcuts

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