package main import ( "fmt" "io" "os" ) func main() { source, err := os.Open("test.txt") if err != nil { panic(err) } defer source.Close() dest, err := os.Create("output.txt") if err != nil { panic(err) } defer dest.Close() _, err = io.Copy(dest, source) if err != nil { panic(err) } fmt.Println("File copied!") }
package main import ( "fmt" "io/ioutil" "net/http" ) func main() { response, err := http.Get("https://golang.org") if err != nil { panic(err) } defer response.Body.Close() body, err := ioutil.ReadAll(response.Body) if err != nil { panic(err) } fmt.Println(string(body)) }Here, we use the `http.Get` function to retrieve the HTTP response from the specified URL. We create a `ReadWriteCloser` interface using the `response.Body` field, which can be read from to retrieve the response data. We then use the `ioutil.ReadAll` function to retrieve all the data from the response body and convert it to a string. Finally, the string is printed to the console. Package library: `net/http`, `ioutil`