Fix lint errors, ensure errors start with 'hostname:'

This commit is contained in:
Pim van Pelt
2025-07-07 09:06:20 +02:00
parent 9a2264e867
commit 3da4de7711
3 changed files with 11 additions and 7 deletions

View File

@ -4,7 +4,7 @@ package main
import (
"fmt"
"io/ioutil"
"os"
"dario.cat/mergo"
"gopkg.in/yaml.v3"
@ -29,7 +29,7 @@ type Device struct {
}
func readYAMLFile(path string) (map[string]interface{}, error) {
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}

View File

@ -217,7 +217,9 @@ func main() {
rootCmd.Flags().StringSliceVar(&hostFilter, "host", []string{}, "Specific host(s) to process (can be repeated, processes all if not specified)")
rootCmd.Flags().IntVar(&parallel, "parallel", 10, "Maximum number of devices to process in parallel")
rootCmd.MarkFlagRequired("yaml")
if err := rootCmd.MarkFlagRequired("yaml"); err != nil {
log.Fatal(err)
}
if err := rootCmd.Execute(); err != nil {
log.Fatal(err)

View File

@ -4,7 +4,6 @@ package main
import (
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
@ -145,11 +144,11 @@ func (rb *RouterBackup) Connect() error {
}
}
key, err := ioutil.ReadFile(keyFile)
key, err := os.ReadFile(keyFile)
if err == nil {
signer, err := ssh.ParsePrivateKey(key)
if err != nil {
fmt.Errorf("unable to parse private key: %v", err)
fmt.Printf("%s: Unable to parse private key: %v\n", rb.hostname, err)
} else {
config.Auth = append(config.Auth, ssh.PublicKeys(signer))
}
@ -268,7 +267,10 @@ func (rb *RouterBackup) BackupCommands(commands []string, excludePatterns []stri
fmt.Fprintf(file, "## COMMAND: %s\n", command)
filteredOutput := filterOutput(output, excludePatterns)
file.WriteString(filteredOutput)
if _, err := file.WriteString(filteredOutput); err != nil {
fmt.Printf("%s: Failed to write output: %v\n", rb.hostname, err)
hasErrors = true
}
file.Close()
successCount++