code: func validateRequest(r *http.Request) (int, error) {
  	if r.Method == http.MethodPut || r.Method == http.MethodDelete {
  		return http.StatusMethodNotAllowed, errors.New("method not allowed")
  	}
  	if r.ContentLength > maxRequestContentLength {
  		err := fmt.Errorf("content length too large (%d>%d)", r.ContentLength, maxRequestContentLength)
  		return http.StatusRequestEntityTooLarge, err
  	}
  	// Allow OPTIONS (regardless of content-type)
  	if r.Method == http.MethodOptions {
  		return 0, nil
  	}
  	// Check content-type
  	if mt, _, err := mime.ParseMediaType(r.Header.Get("content-type")); err == nil {
  		for _, accepted := range acceptedContentTypes {
  			if accepted == mt {
  				return 0, nil
  			}
  		}
  	}
  	// Invalid content-type
  	err := fmt.Errorf("invalid content type, only %s is supported", contentType)
  	return http.StatusUnsupportedMediaType, err
  }
docs: // validateRequest returns a non-zero response code and error message if the
  // request is invalid.