Add KnownHosts.Hosts function
This commit is contained in:
parent
1a3974b3a3
commit
e701ceff71
16
tofu/tofu.go
16
tofu/tofu.go
@ -10,6 +10,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -45,6 +46,21 @@ func (k *KnownHosts) Lookup(hostname string) (Host, bool) {
|
|||||||
return c, ok
|
return c, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hosts returns the known hosts sorted by hostname.
|
||||||
|
func (k *KnownHosts) Hosts() []Host {
|
||||||
|
keys := make([]string, 0, len(k.hosts))
|
||||||
|
for key := range k.hosts {
|
||||||
|
keys = append(keys, key)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
hosts := make([]Host, 0, len(k.hosts))
|
||||||
|
for _, key := range keys {
|
||||||
|
hosts = append(hosts, k.hosts[key])
|
||||||
|
}
|
||||||
|
return hosts
|
||||||
|
}
|
||||||
|
|
||||||
// WriteTo writes the list of known hosts to the provided io.Writer.
|
// WriteTo writes the list of known hosts to the provided io.Writer.
|
||||||
func (k *KnownHosts) WriteTo(w io.Writer) (int64, error) {
|
func (k *KnownHosts) WriteTo(w io.Writer) (int64, error) {
|
||||||
k.mu.RLock()
|
k.mu.RLock()
|
||||||
|
Loading…
Reference in New Issue
Block a user