Standard library / net/http/httptest
httptest.ResponseRecorder.WriteString()
Records string content and returns the byte count. Expected stdout: '2 Go\n'.
Formal Syntax & Structure
go syntaxgo
func (rw *ResponseRecorder) WriteString(str string) (int, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| str | string | Input value of the declared type; see the usage example. |
Return Value
(int, error)
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/http/httptest")
func main() { w := httptest.NewRecorder() n := must(w.WriteString("Go")) fmt.Println(n, w.Body.String())}
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}