Browse Source

jsonDecoder doesn't need to be exported

Piotr Czajkowski 3 years ago
parent
commit
d5b65a9d6b
4 changed files with 7 additions and 8 deletions
  1. 4 5
      app.go
  2. 1 1
      search.go
  3. 1 1
      search_test.go
  4. 1 1
      tm.go

+ 4 - 5
app.go

@@ -24,13 +24,12 @@ func (app *Application) setBaseURL(url string) {
 	app.BaseURL = url
 }
 
-// JSONDecoder decodes json to given interface, borrowed from SO.
-func JSONDecoder(data io.ReadCloser, target interface{}) {
+func jsonDecoder(data io.ReadCloser, target interface{}) {
 	decoder := json.NewDecoder(data)
 
 	err := decoder.Decode(target)
 	if err != nil {
-		log.Printf("Error reading json: %v", err)
+		log.Printf("Error reading json: %s", err)
 	}
 }
 
@@ -43,7 +42,7 @@ func (app *Application) LoadLanguages() {
 	defer data.Close()
 
 	app.Languages = make(map[string]string)
-	JSONDecoder(data, &app.Languages)
+	jsonDecoder(data, &app.Languages)
 }
 
 func (app Application) checkLanguage(language string) bool {
@@ -69,7 +68,7 @@ func (app *Application) Login() {
 	}
 	defer resp.Body.Close()
 
-	JSONDecoder(resp.Body, &app)
+	jsonDecoder(resp.Body, &app)
 
 	app.AuthString = "?authToken=" + app.AccessToken
 	log.Println(app.AuthString, resp.Status)

+ 1 - 1
search.go

@@ -114,7 +114,7 @@ func (app *Application) Search(TMs []TM, text string) SearchResults {
 		}
 
 		var tempResults ResultsFromServer
-		JSONDecoder(resp.Body, &tempResults)
+		jsonDecoder(resp.Body, &tempResults)
 
 		if tempResults.TotalConcResult > 0 {
 			tmResults := getCleanedResults(tempResults, tm.FriendlyName)

+ 1 - 1
search_test.go

@@ -58,7 +58,7 @@ func TestSearch(t *testing.T) {
 	defer tmsJSON.Close()
 
 	var tms []TM
-	JSONDecoder(tmsJSON, &tms)
+	jsonDecoder(tmsJSON, &tms)
 
 	testSourceSegment1 := "<bpt i='1' type='bold'>{}</bpt>Something Test/ Whatever<ept i='1'>{}</ept>"
 	testSourceSegment2 := "<bpt i='1' type='bold'>{}</bpt>Another Test/ Anything<ept i='1'>{}</ept>"

+ 1 - 1
tm.go

@@ -41,7 +41,7 @@ func (app *Application) GetTMs(language string) []TM {
 	}
 
 	var results []TM
-	JSONDecoder(resp.Body, &results)
+	jsonDecoder(resp.Body, &results)
 
 	return results
 }