func readFile(path string) ([]byte, error) { file, err := os.Open(path) if err != nil { return nil, err } defer file.Close() data, err := ioutil.ReadAll(file) if err != nil { return nil, err } return data, nil }
func makeRequest(url string) error { resp, err := http.Get(url) if err != nil { return err } defer resp.Body.Close() data, err := ioutil.ReadAll(resp.Body) if err != nil { return err } fmt.Println(string(data)) return nil }This code makes a GET request to the given URL using the http package, and reads the response body using the ioutil package's ReadAll function. The response body is closed after reading using the defer statement. Finally, it prints out the response body as a string.