convert string to io reader golang
strings.NewReader(s)
convert string to io reader golang
strings.NewReader(s)
golang io.readcloser to string
package main
import (
"fmt"
"net/http"
"bytes"
)
func main() {
response, _ := http.Get("https://golangcode.com/")
// The line below would fail because Body = io.ReadCloser
// fmt.Printf(response.Body)
// ...so we convert it to a string by passing it through
// a buffer first. A 'costly' but useful process.
buf := new(bytes.Buffer)
buf.ReadFrom(response.Body)
newStr := buf.String()
fmt.Printf(newStr)
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us