Documentation
¶
Index ¶
- Variables
- func AppName() string
- func FormatCmd(tags Tags) (string, error)
- func FormatConsul(tags Tags) (string, error)
- func FormatEnv(tags Tags) (string, error)
- func FormatJson(tags Tags) (string, error)
- func FormatSystemd(tags Tags) (string, error)
- func FormatTelegraf(tags Tags) (string, error)
- func FormatToml(tags Tags) (string, error)
- func FormatYaml(tags Tags) (string, error)
- func Version() string
- type Format
- type Manager
- func (m *Manager) ConfigTags() Tags
- func (m *Manager) GetLogger() *slog.Logger
- func (m *Manager) GetTag(key string, def string) string
- func (m *Manager) GetTags(regex bool, pick string, omit string) Tags
- func (m *Manager) LoadFiles() error
- func (m *Manager) PrefixTags(tags Tags, prefix string) Tags
- func (m *Manager) RemoteTags() Tags
- func (m *Manager) RemoveTag(key string) string
- func (m *Manager) Reset()
- func (m *Manager) SaveFiles() error
- func (m *Manager) SetLogger(l *slog.Logger)
- func (m *Manager) SetTag(key string, val string) string
- func (m *Manager) SuffixTags(tags Tags, suffix string) Tags
- func (m *Manager) SystemTags() Tags
- func (m *Manager) UpdateRemote(timeout time.Duration, retry time.Duration, requiredKeys []string) error
- type Tags
Constants ¶
This section is empty.
Variables ¶
var Formats = map[string]Format{ "json": FormatJson, "yaml": FormatYaml, "yml": FormatYaml, "toml": FormatToml, "cmd": FormatCmd, "env": FormatEnv, "systemd": FormatSystemd, "telegraf": FormatTelegraf, "consul": FormatConsul, }
Formats is a registry of tag formatting functions.
var InvalidConsulMetaKey = regexp.MustCompile("[^a-zA-Z0-9_-]")
InvalidConsulMetaKey targets invalid chars in metadata keys
Functions ¶
func FormatCmd ¶ added in v0.2.0
FormatCmd attempts to convert tags into a string compatible with shell environment variables that are combined on a single line. Returns error if the conversion fails.
func FormatConsul ¶
FormatConsul attempts to convert tags into a string which could be stored as a config file for Consul by HashiCorp. Returns error if the conversion fails.
func FormatEnv ¶
FormatEnv attempts to convert tags into a string compatible with shell environment variables that are exported on separate lines. Returns error if the conversion fails.
func FormatJson ¶
FormatJson attempts to convert tags into a JSON string. Returns error if the conversion fails.
func FormatSystemd ¶ added in v0.2.0
FormatSystemd attempts to convert tags into a string compatible with systemctl set-environment statements. Returns error if the conversion fails.
func FormatTelegraf ¶
FormatTelegraf attempts to convert tags into a string which could be stored as a config file for Telegraf by InfluxData. Returns error if the conversion fails.
func FormatToml ¶
FormatToml attempts to convert tags into a TOML string. Returns error if the conversion fails.
func FormatYaml ¶
FormatYaml attempts to convert tags into a YAML string. Returns error if the conversion fails.
Types ¶
type Format ¶
Format is a type that defines a function signature for formatting tags into a specific string format.
type Manager ¶
type Manager struct {
// The directory for the config files
ConfigDir string
// The directory for the system files
SystemDir string
// contains filtered or unexported fields
}
Manager maintains instance information for the type which includes in-memory representations of the tags as well as configurable options.
func NewManager ¶
func NewManager() *Manager
NewManager initializes a new Manager with default configurations and directories.
func (*Manager) ConfigTags ¶
ConfigTags returns the Manager's config tags.
func (*Manager) GetTag ¶
GetTag returns a tag by its key from system, config, or remote tags, in that order. If the key doesn't exist in any of the tag sets, it returns the default value.
func (*Manager) GetTags ¶
GetTags returns the combined set of config, system, and remote tags, but it filters the tags based on regular expressions provided in the "pick" and "omit" parameters. If the "regex" parameter is set to false, the function treats the "pick" and "omit" parameters as comma-separated lists of exact keys to include or exclude, respectively.
func (*Manager) LoadFiles ¶
LoadFiles reads files from the Manager's ConfigDir and SystemDir and stores their contents in the Manager's internal config, remote, and system tags.
func (*Manager) PrefixTags ¶ added in v0.2.0
PrefixTags returns new tags based on the specified tags but with each key prepended with prefix string
func (*Manager) RemoteTags ¶
RemoteTags returns the Manager's remote tags.
func (*Manager) RemoveTag ¶
RemoveTag removes a tag with the specified key from the system tags. It returns the previous value of the tag, or an empty string if the tag did not exist.
func (*Manager) Reset ¶
func (m *Manager) Reset()
Reset clears the current in-memory representation of this Manager's config, remote, and system tags.
func (*Manager) SaveFiles ¶
SaveFiles saves the current state of the Manager's remote and system tags to corresponding files in the SystemDir. Before writing new data, it attempts to create a backup of the existing files.
func (*Manager) SetLogger ¶
SetLogger sets a new logger for the Manager. If the provided logger is nil, it will reset it to default.
func (*Manager) SetTag ¶
SetTag sets a tag with the specified key and value in the system tags. It returns the previous value of the tag, or an empty string if the tag did not exist.
func (*Manager) SuffixTags ¶ added in v0.2.0
SuffixTags returns new tags based on the specified tags but with each key appended with suffix string
func (*Manager) SystemTags ¶
SystemTags returns the Manager's system tags.
func (*Manager) UpdateRemote ¶
func (m *Manager) UpdateRemote(timeout time.Duration, retry time.Duration, requiredKeys []string) error
UpdateRemote fetches remote tags from the instance it's currently running on. This operation may take some time to complete, controlled by timeout. If a retry duration is provided, this function will auto retry for the duration if empty tags are returned. A bounded exponential backoff strategy is employed. If the required keys slice is provided, the function will keep retrying until all the required keys are present in the fetched tags or until the retry duration is reached.