cfg

package module
v0.0.0-...-2aaeead Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: BSD-3-Clause Imports: 21 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultValueSize   int = 5000
	DefaultCommentSize int = 200
	DefaultNameSize    int = 80

	// Loading of empty files fails on default.
	DefaultAllowEmpty bool

	// Execution is disabled (false) on default.
	// You can overwrite this on *Data type calls by prefixing Exec().
	DefaultExec bool
	// DefaultExecTime is the timeout for every single command execution.
	// You can disable command execution entirely by setting it to 0.
	DefaultExecTime time.Duration = time.Second * 2

	//Verbosity com.Level = com.Common
	Verbosity com.Level = com.ErrorsOnly

	// Format to use for type time.Time
	DateFormat string = "2006-01-02T15:04:05ZMST"
)

Functions

This section is empty.

Types

type Config

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

Config holds the data trees, settings and file information.

func File

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

func Load

func Load(r io.Reader) (*Config, error)

Load takes a reader and returns that data as a *Config.

func New

func New() *Config

New create a pointer to an empty Config filled by global default values.

func (*Config) Delete

func (c *Config) Delete(section, key string) error

Delete removes the key with all values from the given section.

func (*Config) Empty

func (c *Config) Empty() *Config

Empty allows the Load/Reload of empty Config files.

func (*Config) Environ

func (c *Config) Environ(use []string) *Config

Environ uses the given environment variables on execution of commands.

func (*Config) ExecDisable

func (c *Config) ExecDisable() *Config

ExecDisable disables command execution.

func (*Config) ExecEnable

func (c *Config) ExecEnable() *Config

ExecEnable enables command execution.

func (*Config) Exists

func (c *Config) Exists(section, key string) bool

Exists checks if the key in that given section exists.

func (*Config) File

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

func (*Config) Get

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

Get returns the plain string value.

func (*Config) Hash

func (c *Config) Hash() ([]byte, error)

Hash returns the SHA3-256 value for the content of *Config.

func (*Config) Keys

func (c *Config) Keys(section string) []string

Keys returns all available keys of the given section.

func (*Config) Load

func (c *Config) Load(r io.Reader) error

Load takes a reader and overwrites the given *Config.

func (*Config) Map

func (c *Config) Map(conversions map[string]Conversion) map[string]any

Map returns the content of *Config in a map converting values to the types given in the conversions map.

func (*Config) Modified

func (c *Config) Modified() bool

Modified returns a boolean to indicate if the *Config was altered since the initial Load/New/File call.

func (*Config) Reload

func (c *Config) Reload(r io.Reader) error

Reload takes data from a Reader and replaces *Config content with the new data.

func (*Config) Save

func (c *Config) Save(files ...string) error

Save writes the Config to the file it was loaded from or if the optional string value files was defined it's written to each of those files. If you want write to multiple files and include the file it was loaded from, you have to specify it explicitly among files.

func (*Config) Section

func (c *Config) Section(name string) *Data

Section returns a Data object for the named section in Config.

func (*Config) Sections

func (c *Config) Sections() []string

Sections returns all available sections.

func (*Config) Set

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

func (*Config) Store

func (c *Config) Store(w io.Writer) error

Store writes the Config to a Writer.

func (*Config) Struct

func (c *Config) Struct(x any, section string) any

Struct returns an interface of type x with the key/values queried by the given tags. Section replaces "main" as default section value if defined.

type Conversion

type Conversion struct {
	Exec bool
	Kind Kind
}

type Data

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

Data is a part of the Config defined by the given *Config.Section(name) call that representing a section.

func (*Data) Bind

func (d *Data) Bind(key string) *bind.Target

Bind returns the key's value as *bind.Target for that given section.

func (*Data) Binds

func (d *Data) Binds(key string) []*bind.Target

Binds returns the key's value as []*bind.Target for that given section.

Structure: One per slice, separated by spaces.

func (*Data) Bool

func (d *Data) Bool(key string) bool

Bool returns the key's value as bool for that given section.

func (*Data) Bools

func (d *Data) Bools(key string) []bool

Bools returns the key's value as []bool for that given section.

Structure: One per slice, separated by spaces.

func (*Data) Bytes

func (d *Data) Bytes(key string) []byte

Bytes returns the key's value base91 decoded as []byte for that given section.

func (*Data) CIDR

func (d *Data) CIDR(key string) netip.Prefix

CIDR returns the key's value as netip.Prefix for that given section.

func (*Data) CIDRs

func (d *Data) CIDRs(key string) []netip.Prefix

CIDRs returns the key's value as []netip.Prefix for that given section.

Structure: One per slice, separated by spaces.

func (*Data) Commands

func (d *Data) Commands(key string) []string

Commands returns all available commands for the given key of section.

func (*Data) Comments

func (d *Data) Comments(key string) []string

Comments returns the the comments associated with the given key of section.

func (*Data) Custom

func (d *Data) Custom(key string, value any) error

Custom returns the base91 encoded value and decodes it to your pointer value.

func (*Data) Date

func (d *Data) Date(key string) time.Time

Date returns the key's value as time.Time for that given section. See DateFormat.

func (*Data) Dates

func (d *Data) Dates(key string) []time.Time

Dates returns the key's value as []time.Time for that given section.

Structure: See Dateformat separated by spaces.

func (*Data) Delete

func (d *Data) Delete(key string) error

Delete removes the key with all values.

func (*Data) Duration

func (d *Data) Duration(key string) time.Duration

Duration returns the key's value as time.Duration for that given section.

func (*Data) Durations

func (d *Data) Durations(key string) []time.Duration

Durations returns the key's value as []time.Duration for that given section.

Structure: One per slice, separated by spaces.

func (*Data) Exec

func (d *Data) Exec() *Data

Exec enables command execution for this copy and it's method calls.

func (*Data) Exists

func (d *Data) Exists(key string) bool

Exists checks if the key exists.

func (*Data) Float

func (d *Data) Float(key string) float64

Float returns the key's value as float64 for that given section.

func (*Data) Floats

func (d *Data) Floats(key string) []float64

Floats returns the key's value as []float64 for that given section.

Structure: One per slice, separated by spaces.

func (*Data) Get

func (d *Data) Get(key string) (string, error)

Get returns the plain string value.

func (*Data) IP

func (d *Data) IP(key string) netip.Addr

IP returns the key's value as netip.Addr for that given section.

func (*Data) IPs

func (d *Data) IPs(key string) []netip.Addr

IPs returns the key's value as []netip.Addr for that given section.

Structure: One per slice, separated by spaces.

func (*Data) Int

func (d *Data) Int(key string) int64

Int returns the key's value as int64 for that given section.

func (*Data) Ints

func (d *Data) Ints(key string) []int64

Ints returns the key's value as []int64 for that given section.

Structure: One per slice, separated by spaces.

func (*Data) Keys

func (d *Data) Keys() []string

Keys returns all available keys of the given section.

func (d *Data) Link(key string) *url.URL

Link returns the key's value as *url.URL for that given section.

func (d *Data) Links(key string) []*url.URL

Links returns the key's value as *url.URL for that given section.

Structure: One Link per line

func (*Data) Run

func (d *Data) Run(key string) (string, []int, error)

Run executes the value of key and returns the string value and return codes.

func (*Data) Set

func (d *Data) Set(key string, value any) error

func (*Data) String

func (d *Data) String(key string) string

String returns the key's value as string for that given section.

func (*Data) Strings

func (d *Data) Strings(key string) []string

Strings returns the key's fields as []string for that given section.

Structure: One line per slice.

type Filter

type Filter func(section, key, value string, found bool, data any) (string, error)

Filter / post get query

type Kind

type Kind uint8
const (
	String Kind = iota
	Strings
	Bool
	Bools
	Int
	Ints
	Float
	Floats
	Bytes
	Date
	Dates
	Duration
	Durations
	IP
	IPs
	Link
	Links
	Bind
	Binds
	CIDR
	CIDRs
)

func ParseKind

func ParseKind(kind string) Kind

ParseKind converts a string value to a Kind.

func (Kind) String

func (k Kind) String() string

String implements the Stringer interface for Kind.

type Query

type Query func(section, key string, exec bool, data any) (string, string, bool, error)

Query / pre get query

type Result

type Result func(section, key string, value []string, data any) (string, string, []string, error)

Result / pre set call

Directories

Path Synopsis
acme module
argon2i module
reload module
totp module

Jump to

Keyboard shortcuts

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