Standard library / net/http

http.MaxBytesError

Reports an exceeded request body byte limit through its Limit field. Expected stdout: '3\n'.

Formal Syntax & Structure

go syntaxgo
type MaxBytesError struct {  Limit int64}

Working Example

Example Snippetgo
package main
import (  "errors"  "fmt"  "io"  "net/http"  "net/http/httptest"  "strings")
func main() {  r := httptest.NewRequest("POST", "/", strings.NewReader("abcdef"))  b := http.MaxBytesReader(httptest.NewRecorder(), r.Body, 3)  defer b.Close()  _, e := io.ReadAll(b)  var x *http.MaxBytesError  if !errors.As(e, &x) {    panic("wrong error")  }  fmt.Println(x.Limit)}
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