manager

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
var InvalidConsulMetaKey = regexp.MustCompile("[^a-zA-Z0-9_-]")

InvalidConsulMetaKey targets invalid chars in metadata keys

Functions

func AppName

func AppName() string

AppName returns the manager executable name

func FormatCmd added in v0.2.0

func FormatCmd(tags Tags) (string, error)

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

func FormatConsul(tags Tags) (string, error)

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

func FormatEnv(tags Tags) (string, error)

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

func FormatJson(tags Tags) (string, error)

FormatJson attempts to convert tags into a JSON string. Returns error if the conversion fails.

func FormatSystemd added in v0.2.0

func FormatSystemd(tags Tags) (string, error)

FormatSystemd attempts to convert tags into a string compatible with systemctl set-environment statements. Returns error if the conversion fails.

func FormatTelegraf

func FormatTelegraf(tags Tags) (string, error)

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

func FormatToml(tags Tags) (string, error)

FormatToml attempts to convert tags into a TOML string. Returns error if the conversion fails.

func FormatYaml

func FormatYaml(tags Tags) (string, error)

FormatYaml attempts to convert tags into a YAML string. Returns error if the conversion fails.

func Version

func Version() string

Version returns the current manager version

Types

type Format

type Format func(Tags) (string, error)

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

func (m *Manager) ConfigTags() Tags

ConfigTags returns the Manager's config tags.

func (*Manager) GetLogger

func (m *Manager) GetLogger() *slog.Logger

GetLogger returns the current logger from the Manager.

func (*Manager) GetTag

func (m *Manager) GetTag(key string, def string) string

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

func (m *Manager) GetTags(
	regex bool,
	pick string,
	omit string,
) Tags

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

func (m *Manager) LoadFiles() error

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

func (m *Manager) PrefixTags(tags Tags, prefix string) Tags

PrefixTags returns new tags based on the specified tags but with each key prepended with prefix string

func (*Manager) RemoteTags

func (m *Manager) RemoteTags() Tags

RemoteTags returns the Manager's remote tags.

func (*Manager) RemoveTag

func (m *Manager) RemoveTag(key string) string

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

func (m *Manager) SaveFiles() error

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

func (m *Manager) SetLogger(l *slog.Logger)

SetLogger sets a new logger for the Manager. If the provided logger is nil, it will reset it to default.

func (*Manager) SetTag

func (m *Manager) SetTag(key string, val string) string

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

func (m *Manager) SuffixTags(tags Tags, suffix string) Tags

SuffixTags returns new tags based on the specified tags but with each key appended with suffix string

func (*Manager) SystemTags

func (m *Manager) SystemTags() Tags

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.

type Tags

type Tags map[string]string

Tags describe a map of key/value pairs

Jump to

Keyboard shortcuts

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