diff --git a/main.go b/main.go index df9a9ca..dfb771c 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,6 @@ import ( "encoding/json" "flag" "fmt" - "io" "log" "net/http" "net/url" @@ -42,11 +41,10 @@ func main() { var encinput = url.PathEscape(input) var queryURL = instance + "?engine=" + engine + "&from=" + from + "&to=" + to + "&text=" + encinput // Begin the request and process the response - req, err := http.Get(queryURL) + resp, err := http.Get(queryURL) sanityCheck(err) - defer req.Body.Close() - resp, err := io.ReadAll(req.Body) - _ = json.Unmarshal([]byte(resp), &translate) + defer resp.Body.Close() + _ = json.NewDecoder(resp.Body).Decode(&translate) sanityCheck(err) // Pretty-print both the input and the output given. fmt.Printf("Input: %v\n", input)