title: EOF when posting JSON to localhost Go backend using VueJS
body: <p>I'm setting up a login system using VueJS for frontend and Go for backend. I'm currently stuck at POSTing the username &amp; password to the backend in JSON format.</p>
  
  <p>Currently I am attempting to post using fetch, after having bad luck with Axios earlier.</p>
  
  <p>Post method:</p>
  
  <pre><code>fetch("http://localhost:9444/login", {
                      method: "post",
                      headers: {
                          'Accept': 'application/json',
                          'Content-Type': 'application/json'
                      },
  
                      body: JSON.stringify({
                          "emailAddress": "myName",
                          "password": "myPassword"
                      })
                  })
                  .then( (response) =&gt; { 
                  console.log(response)
                  });
  </code></pre>
  
  <p>Which I then route in my backend like:</p>
  
  <pre><code>r := mux.NewRouter().StrictSlash(true)
  r.HandleFunc("/login", models.LoginHandler(db)).Methods("POST", "OPTIONS")
  </code></pre>
  
  <p>LoginHandler:</p>
  
  <pre><code>func LoginHandler(db *sql.DB) func(w http.ResponseWriter, req *http.Request) {
      return func(w http.ResponseWriter, req *http.Request) {
          // w.Header().Set("Access-Control-Allow-Origin", "*")
          // w.Header().Set("Access-Control-Allow-Headers", "*")
          w.Header().Set("Content-Type", "application/json; charset=utf-8")
          w.Header().Set("Access-Control-Allow-Origin", "*")
  
          // Initialize loginInfo
          loginInfo := LoginInfo{}
  
          // Decode request body using JSON
          err := json.NewDecoder(req.Body).Decode(&amp;loginInfo)
          if err != nil {
              panic(err)
          }
  
          println(loginInfo.EmailAddress)
          println(loginInfo.Password)
  
          w.WriteHeader(http.StatusOK)
          w.Write([]byte("Test message."))
      }
  }
  </code></pre>
  
  <p>Which currently results in crashing on the decoding part like so:</p>
  
  <pre><code>2019/11/12 14:45:53 http: panic serving [::1]:57224: EOF
  goroutine 35 [running]:
  net/http.(*conn).serve.func1(0xc000196000)
          c:/go/src/net/http/server.go:1769 +0x140
  panic(0x8be000, 0xc00005c050)
          c:/go/src/runtime/panic.go:522 +0x1c3
  _/H_/Development/clientportal/backend/models.LoginHandler.func1(0x9f7360, 0xc0001be000, 0xc0001a8200)
  ...
  </code></pre>
  
  <p>What could cause the constant EOF errors? I've tested (and confirmed correct functionality) using postman:</p>
  
  <pre><code>{
      "emailAddress": "login",
      "password": "passw"
  }
  </code></pre>
  
  <p>Which returns status 200 correctly.</p>