Documentation
¶
Index ¶
- Variables
- func DurationWithDefaultMinMax(s *string, defaultD, minD, maxD time.Duration) (time.Duration, error)
- func Format(c Converter, v any) string
- func FormatDuration(d time.Duration) string
- func FormatSize(n int64) string
- func Name(c Converter) string
- func ParseDuration(s string) (time.Duration, error)
- func ReadFile(fs embed.FS, s string) string
- func Register(c Converter)
- type Converter
- type Formatter
- type TBool
- type TDuration
- type TFileMode
- type TFloat64
- type TGroup
- type TInt
- type TInt64
- type TList
- type TListLowercase
- type TSet
- type TShare
- type TShlex
- type TSize
- type TString
- type TTristate
- type TUmask
- type TUser
Constants ¶
This section is empty.
Variables ¶
var DB = map[string]Converter{}
DB is the name-indexed registry of the known converters. It is used to convert back the converter names received from a peer daemon, which may run a different version, so a name may be unknown.
Functions ¶
func DurationWithDefaultMinMax ¶
func DurationWithDefaultMinMax(s *string, defaultD, minD, maxD time.Duration) (time.Duration, error)
DurationWithDefaultMinMax parses a duration string and clamps the result within minD and maxD or returns defaultD. If s is nil or empty, defaultD is returned, clamped within the range defined by minD and maxD.
func Format ¶
Format writes the value the converter c converted the way a configuration writes it. A converter with no Formatter, and no converter at all, write the value as it is: a list as its words, a pointer as what it points to, nothing as the empty text.
func FormatDuration ¶
FormatDuration writes a duration with its zero units dropped: 2m, 1h30m, 1h, 500ms, 0s.
func FormatSize ¶
FormatSize writes a number of bytes in the largest binary unit it is a whole number of.
func ParseDuration ¶
ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
Types ¶
type Converter ¶
var ( String Converter = TString{} Int Converter = TInt{} Int64 Converter = TInt64{} Float64 Converter = TFloat64{} Bool Converter = TBool{} List Converter = TList{} ListLowercase Converter = TListLowercase{} Set Converter = TSet{} Shlex Converter = TShlex{} Duration Converter = TDuration{} Umask Converter = TUmask{} Size Converter = TSize{} FileMode Converter = TFileMode{} Tristate Converter = TTristate{} User Converter = TUser{} Group Converter = TGroup{} )
The exported converters are the singletons the keyword definitions and the callers must reference. Referencing them instead of their name makes a typo a compilation error instead of a runtime panic.
func Get ¶
Get returns the converter registered as s. An empty s means "no conversion", and returns a nil Converter and true.
Unlike a name lookup in a keyword definition, which is now a compile-time check, s may come from a untrusted source like a peer daemon keyword definition, so an unknown name must not panic.
type Formatter ¶
Formatter is a converter writing a value it converted back the way a configuration writes it: a duration as 2m, a size as 5g.
The converted value is what a program reads, a count of nanoseconds or of bytes. The text is what a person reads, and converts back to the same value.
type TDuration ¶
type TDuration struct{}
func (TDuration) Convert ¶
Convert converts duration string to *time.Duration
nil is returned when duration is unset Default unit is second when not specified
type TFileMode ¶
type TFileMode struct{}
type TListLowercase ¶
type TListLowercase struct{}
func (TListLowercase) String ¶
func (t TListLowercase) String() string
type TShare ¶
type TShare struct{}
type TShlex ¶
type TShlex struct{}
type TSize ¶
type TSize struct{}