Question: The below Golang code has several errors. Please identify the errors and re - write the code to improve efficiencies and align better with Golang

The below Golang code has several errors. Please identify the errors and re-write the code to improve efficiencies and align better with Golang concepts. Submit your code submission in the answer below.
input.txt test input '{\"location\": \"foo\"}'{\"location\": \"foo.com\"}{\"location\": \"bar.com\"}{\"location\": \"httpbar.com\"}{\"location\": \"https://bar.com\"}---- package main import (\"bytes\"\"context\"\"encoding/json\"\"fmt\"\"io\"\"log\"\"net/http\"\"os\"\"strings\") var buf *bytes.Buffer func main(){ data, err := os.ReadFile(\"./input.txt\") if err != nil { log.Fatal(err)} lines := strings.Split(string(data),\"
\") for _, line := range lines { go func(){ data, err := getData(line) if err != nil { log.Printf(\"unable to get status: %v\", err)} if data.(string)==\"foo\"{ fmt.Printf(\"data found: %s\", data) os.Exit(0)}}()}} func getData(line string)(any, error){ var location struct { URL string } if err := json.Unmarshal([]byte(line), &location); err != nil {} req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, location.URL, nil) if err != nil { return nil, err } c := &http.Client{} res, err := c.Do(req) if err != nil { return nil, err } if _, err := io.Copy(buf, res.Body); err != nil { return nil, err } var payload struct { Data string `bson:\"data\"`} if err := json.Unmarshal(buf.Bytes(), &payload); err != nil { return nil, err } return payload.Data, nil }
*
Your answer

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!