~nesv/govern

1ae1b3dbdb2bf2ba2ca4f9b56a0a8a6b2f370851 — Nick Saika 1 year, 6 months ago d2433fc
internal/facts: Add method to get fact names

After the facts.Facts type has been populated with all discovered facts
on a host, for convenience, this commit adds a way to retrieve the names
of all of those facts.
1 files changed, 13 insertions(+), 0 deletions(-)

M internal/facts/facts.go
M internal/facts/facts.go => internal/facts/facts.go +13 -0
@@ 172,3 172,16 @@ func (f *Facts) Get(name string) (string, error) {
	p, err := io.ReadAll(fact)
	return string(p), errors.Wrap(err, "read fact")
}

// Names returns the names of all available facts.
func (f *Facts) Names() []string {
	f.mu.RLock()
	defer f.mu.RUnlock()

	names := make([]string, 0, len(f.facts))
	for name := range f.facts {
		names = append(names, name)
	}

	return names
}