title: What is the best way to check for empty request Body?
body: <p>From the <a href="https://golang.org/src/net/http/request.go" rel="noreferrer">documentation</a> it states that </p>
  
  <blockquote>
    <p>For server requests the Request Body is always non-nil but will return EOF immediately when no body is present.</p>
  </blockquote>
  
  <p>For ContentLength, the documentation states</p>
  
  <blockquote>
    <p>For client requests, a value of 0 means <strong>unknown</strong> if Body is not nil.</p>
  </blockquote>
  
  <p>So is it better to check for ContentLength </p>
  
  <pre><code>r *http.Request
  if r.ContentLength == 0 {
    //empty body
  }
  </code></pre>
  
  <p>or to check EOF</p>
  
  <pre><code>type Input struct {
      Name *string `json:"name"`
  }
  
  input := new(Input)
  
  if err := json.NewDecoder(r.Body).Decode(input); err.Error() == "EOF" {
   //empty body
  }
  </code></pre>