From 1d2d7d2020632a3a3541c68f29db26ef73849fe2 Mon Sep 17 00:00:00 2001 From: "koizumi.aoi" Date: Sat, 17 Dec 2022 16:57:12 +0000 Subject: [PATCH] How can you be in two places at once when you're not anywhere at all? git-svn-id: file:///srv/svn/repo/suwako/trunk@8 0b558ee1-521d-8b46-a41b-40029c97c055 --- main.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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)