Prechádzať zdrojové kódy

Close only after checking error

Piotr Czajkowski 3 rokov pred
rodič
commit
7ca8f326b7
2 zmenil súbory, kde vykonal 2 pridanie a 2 odobranie
  1. 1 1
      app.go
  2. 1 1
      search_test.go

+ 1 - 1
app.go

@@ -38,10 +38,10 @@ func JSONDecoder(data io.ReadCloser, target interface{}) {
 // LoadLanguages loads languages from languages.json to map.
 func (app *Application) LoadLanguages() {
 	data, err := os.Open("./html/languages.json")
-	defer data.Close()
 	if err != nil {
 		log.Fatalf("Error reading languages: %v", err)
 	}
+	defer data.Close()
 
 	app.Languages = make(map[string]string)
 	JSONDecoder(data, &app.Languages)

+ 1 - 1
search_test.go

@@ -51,11 +51,11 @@ func TestSearch(t *testing.T) {
 	app.SetBaseURL(server.URL)
 
 	tmsJSON, err := os.Open("./testFiles/tms.json")
-	defer tmsJSON.Close()
 	if err != nil {
 		t.Fatalf("error reading tms: %v", err)
 		return
 	}
+	defer tmsJSON.Close()
 
 	var tms []TM
 	JSONDecoder(tmsJSON, &tms)