Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 rewrite the code to improve efficiencies and align better with Golang concepts. Submit your code submission in the answer below.
input.txt test input location: foolocation: foocomlocation: barcomlocation: httpbarcomlocation: https:barcom package main import bytescontextencodingjsonfmtiolognethttposstrings var buf bytesBuffer func main data, err : osReadFileinputtxt if err nil logFatalerr lines : strings.Splitstringdata
for line : range lines go func data, err : getDataline if err nil logPrintfunable to get status: v err if data.stringfoo fmtPrintfdata found: s data osExit func getDataline stringany error var location struct URL string if err : json.Unmarshalbyteline &location; err nil req, err : httpNewRequestWithContextcontextBackground httpMethodGet, location.URL, nil if err nil return nil, err c : &httpClient res, err : cDoreq if err nil return nil, err if err : ioCopybuf res.Body; err nil return nil, err var payload struct Data string bson:data if err : json.UnmarshalbufBytes &payload; err nil return nil, err return payload.Data, nil
Your answer
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started