tofu: Update documentation

This commit is contained in:
Adnan Maolood 2021-01-14 19:56:04 -05:00
parent da8af5dbcb
commit a0adc42c95

View File

@ -97,8 +97,24 @@ func (k *KnownHosts) Load(path string) error {
// Parse parses the provided io.Reader and adds the parsed hosts to the list. // Parse parses the provided io.Reader and adds the parsed hosts to the list.
// Invalid entries are ignored. // Invalid entries are ignored.
// //
// For more control over errors encountered by parsing, scan the reader with a bufio.Scanner // For more control over errors encountered during parsing, use bufio.Scanner
// and call ParseHost with scanner.Bytes(). // in combination with ParseHost. For example:
//
// var knownHosts tofu.KnownHosts
// scanner := bufio.NewScanner(r)
// for scanner.Scan() {
// host, err := ParseHost(scanner.Bytes())
// if err != nil {
// // handle error
// } else {
// knownHosts.Add(host)
// }
// }
// err := scanner.Err()
// if err != nil {
// // handle error
// }
//
func (k *KnownHosts) Parse(r io.Reader) error { func (k *KnownHosts) Parse(r io.Reader) error {
k.mu.Lock() k.mu.Lock()
defer k.mu.Unlock() defer k.mu.Unlock()