Standard library / net/http

http.NoBody

Reusable empty body implementing io.ReadCloser; reading returns EOF and closing succeeds. Expected stdout: '0 true true\n'.

Formal Syntax & Structure

go syntaxgo
var NoBody noBody

Working Example

Example Snippetgo
package main
import (  "fmt"  "io"  "net/http")
func main() {  b := make([]byte, 1)  n, e := http.NoBody.Read(b)  fmt.Println(n, e == io.EOF, http.NoBody.Close() == nil)}
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)  }}
Go Reference