When you check out the source code both, fmt.Fprint and io.WriteString, need a 
writer as the first argument. Writer is an interface type which provides an 
Write method. And thats exactly what that functions are calling.. the Write 
method of your provided w (which is http.ResponseWriter in your case).

The difference is that fmt.Fprint is formatting the arguments provided first in 
a buffer before calling w.Write.
And io.WriteString is checking if w provides the StringWriter interface and 
calls that instead.

https://golang.org/src/fmt/print.go?s=6466:6527#L221

https://golang.org/src/io/io.go?s=10163:10218#L279

But to answer your question. In your simple case I would use io.WriteString. If 
you have more arguments than you could only use fmt.Fprint or you prepare your 
string by yourself before calling io.WriteString.

Hope that helps (;

Christian

Sent from my iPhone

> On 21. Apr 2019, at 15:59, José Colón <jec....@gmail.com> wrote:
> 
> Hi gophers! Is it better to (w is an http.ResponseWriter)
> 
> fmt.Fprint(w, "Hello world")
> 
> 
> or to 
> 
> io.WriteString(w, "Hello world")
> 
> 
> or doesfmt.Fprint use io.WriteString behind the scenes, and thus they are 
> equivalent?
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to