Browse Source

remove vet warning and uncheck errs

juliendsv 2 years ago
parent
commit
cff52ff0be

+ 4 - 1
chapter2/ansicolor/example/main.go

@@ -7,7 +7,10 @@ import (
 )
 
 func main() {
-	r := ansicolor.ColorText{ansicolor.Red, "I'm red!"}
+	r := ansicolor.ColorText{
+		TextColor: ansicolor.Red,
+		Text:      "I'm red!",
+	}
 
 	fmt.Println(r.String())
 

+ 1 - 1
chapter2/cmdargs/main.go

@@ -30,7 +30,7 @@ func main() {
 			}
 			if len(os.Args) > 3 {
 				if err := f.Parse(os.Args[3:]); err != nil {
-					fmt.Printf("Error parsing params %s, error: %v", os.Args[3:], err)
+					fmt.Fprintf(os.Stderr, "Error parsing params %s, error: %v", os.Args[3:], err)
 					return
 				}
 

+ 3 - 1
chapter2/envvar/config_test.go

@@ -45,7 +45,9 @@ func TestLoadFile(t *testing.T) {
 	defer tf.Close()
 	defer os.Remove(tf.Name())
 
-	tf.Write(bytes.NewBufferString("{}").Bytes())
+	if _, err := tf.Write(bytes.NewBufferString("{}").Bytes()); err != nil {
+		t.Errorf("Error writing into temp file, err: %v ", err)
+	}
 
 	type args struct {
 		path   string

+ 13 - 4
chapter2/envvar/example/main.go

@@ -18,6 +18,8 @@ type Config struct {
 }
 
 func main() {
+	var err error
+
 	// create a temporary file to hold
 	// an example json file
 	tf, err := ioutil.TempFile("", "tmp")
@@ -32,15 +34,22 @@ func main() {
 	secrets := `{
         "secret": "so so secret"
     }`
-	tf.Write(bytes.NewBufferString(secrets).Bytes())
+
+	if _, err = tf.Write(bytes.NewBufferString(secrets).Bytes()); err != nil {
+		panic(err)
+	}
 
 	// We can easily set environment variables
 	// as needed
-	os.Setenv("EXAMPLE_VERSION", "1.0.0")
-	os.Setenv("EXAMPLE_ISSAFE", "false")
+	if err = os.Setenv("EXAMPLE_VERSION", "1.0.0"); err != nil {
+		panic(err)
+	}
+	if err = os.Setenv("EXAMPLE_ISSAFE", "false"); err != nil {
+		panic(err)
+	}
 
 	c := Config{}
-	if err := envvar.LoadConfig(tf.Name(), "EXAMPLE", &c); err != nil {
+	if err = envvar.LoadConfig(tf.Name(), "EXAMPLE", &c); err != nil {
 		panic(err)
 	}
 

+ 2 - 1
chapter2/pipes/pipes.go

@@ -3,13 +3,14 @@ package main
 import (
 	"bufio"
 	"fmt"
+	"io"
 	"os"
 )
 
 // WordCount takes a file and returns a map
 // with each word as a key and it's number of
 // appearances as a value
-func WordCount(f *os.File) map[string]int {
+func WordCount(f io.Reader) map[string]int {
 	result := make(map[string]int)
 
 	// make a scanner to work on the file