Documentation
¶
Index ¶
- func SaveSettings(path string, s Settings) error
- func StringToNrgba(s string) (color.NRGBA, bool)
- func WriteJson(s Settings) ([]byte, error)
- type Builder
- type EnvMatcher
- type Option
- type Process
- type Settings
- func (s Settings) AllKeys() iter.Seq[string]
- func (s Settings) Bool(path string) (bool, bool)
- func (s Settings) Float64(path string) (float64, bool)
- func (s Settings) Int64(path string) (int64, bool)
- func (s Settings) Length(path string) int
- func (s Settings) MustBool(path string, fallback bool) bool
- func (s Settings) MustFloat64(path string, fallback float64) float64
- func (s Settings) MustInt64(path string, fallback int64) int64
- func (s Settings) MustNRGBA(path string, r, g, b, a uint8) color.NRGBA
- func (s Settings) MustRectF(path string, r geo.RectF) geo.RectF
- func (s Settings) MustString(path, fallback string) string
- func (s Settings) NRGBA(path string) (color.NRGBA, bool)
- func (s Settings) Print()
- func (s Settings) RectF(path string) (geo.RectF, bool)
- func (s Settings) String(path string) (string, bool)
- func (s Settings) Strings(path string) []string
- func (s Settings) Subset(path string) Settings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SaveSettings ¶
SaveSettings saves the settings as JSON to the path. It will remove any private keys.
func StringToNrgba ¶
StringToNrgba converts a string to a color. Current supported formats: #FFFFFF #FFFFFFFF
Types ¶
type Builder ¶
type Builder interface {
// Settings answers the raw settings. Generally treat this
// as read-only, and use AddSettings() to make any changes.
Settings() map[string]any
// NewSettings answers a new empty settings.
NewSettings() map[string]any
// AddSettings adds the new settings to the settings being built.
AddSettings(map[string]any)
}
Builder is used to add new settings during a Settings construction.
type EnvMatcher ¶
type EnvMatcher interface {
// Answer a key if a match, or else "". The key
// might be the same key in the args, or it might be modified.
Match(key string) (string, error)
}
EnvMatcher is used by WithEnv to accept env vars and potentially modify the name.
func EnvPattern ¶
func EnvPattern(pattern string) EnvMatcher
EnvPattern loads all env vars that match the pattern into the Settings. See path.Match() for match rules.
func EnvPrefix ¶
func EnvPrefix(prefix string) EnvMatcher
EnvPrefix loads all env vars that match the prefix into the Settings. The prefix will be stripped.
type Option ¶
Option used during construction of a Settings. Clients can add to the settings with the Builder.
func WithFS ¶
WithFS loads all files that match the pattern into the Settings. All matched files must be in JSON format. See path.Match() for match rules.
func WithMap ¶
WithMap adds all keys in the supplied map. Note this is only a shallow copy of the top layer, anything below that is the original reference.
func WithSettings ¶
WithSettings acts as a deep copy on src.
func WithString ¶
type Settings ¶
type Settings struct {
// contains filtered or unexported fields
}
Settings stores a tree of settings values, accessed via a path syntax ("path/to/value"). Settings are immutable. Modifications must be made via creating a new Settings.
func NewEmptySettings ¶
func NewEmptySettings() Settings
func NewSettings ¶
func (Settings) Bool ¶
Bool answers the bool value at the given path. The value must be a bool, a string (with value "true" or "t") or an element of a slice (for example, if the Settings contains "fruits": ["apple", "orange"], then Bool("fruits/apple") will return true).
func (Settings) Length ¶
Length answers the length of the slice at path, or 0 if path is not a slice.
func (Settings) MustBool ¶
MustBool answers the bool value at the given path or fallback if path is absent.
func (Settings) MustFloat64 ¶
MustFloat64 answers the bool value at the given path or fallback if path is absent.
func (Settings) MustInt64 ¶
MustInt64 answers the bool value at the given path or fallback if path is absent.
func (Settings) MustNRGBA ¶
MustNRGBA answers the NRGBA value at the given path or fallback if path is absent. Path must point to a hex value containing rgba components, i.e. "#ffffff" or "#ffffffff"
func (Settings) MustRectF ¶
MustRectF returns a rect. The path must point to the parent of keys that can be "l", "t", "r", "b", or some combination (i.e. "lr").
func (Settings) MustString ¶
MustString answers the string value at the given path or fallback if path is absent.
func (Settings) NRGBA ¶
NRGBA answers the NRGBA value at the given path. Path must point to a hex value containing rgba components, i.e. "#ffffff" or "#ffffffff"
func (Settings) RectF ¶
MustRectF returns a rect. The path must point to the parent of keys that can be "l", "t", "r", "b", or some combination (i.e. "lr").