title: How to read cookies?
body: <p>I set a cookie from javascript such as:</p>
  <pre><code>setCookie(&quot;appointment&quot;, JSON.stringify({
                  appointmentDate: selectedDay.date,
                  appointmentStartMn: appointment.mnRange[0],
                  appointmentId: appointment.id || 0,
                  appointmentUserId: appointment.user.id || 0
            })
  );
  </code></pre>
  <p>After cookie is set I want to redirect the user to a booking page:</p>
  <pre><code>window.location.href = &quot;https://localhost:8080/booking/&quot;
  </code></pre>
  <p>The setCookie function:</p>
  <pre><code>function setCookie(cookieName, cookieValue) {
      document.cookie = `${cookieName}=${cookieValue};secure;`;
  }
  </code></pre>
  <p>I'd like to retrieve that cookie from my go backend but I can't figure out how to do this. I've read about this question since I've never used cookies before but the answers seems to tell that I don't have to do much aside from setting document.cookie.</p>
  <p>In my browser storage I can see the cookie is indeed set as expected.</p>
  <p>In my Go back end I want to print the cookie:</p>
  <pre><code>r.HandleFunc(&quot;/booking/&quot;, handler.serveTemplate)
  
  func (handler *templateHandler) serveTemplate(w http.ResponseWriter, r *http.Request) {
      c, err := r.Cookie(&quot;appointment&quot;)
      if err != nil {
          fmt.Println(err.Error())
      } else {
          fmt.Println(c.Value)
      }
  }
  
  //output http: named cookie not present
  </code></pre>
  <p>What is the specific I am missing ? I think I'm confusing local/http cookie but how to achieve the reading of client set cookies?</p>
  <p><strong>UPDATE (see answer for more)</strong></p>
  <p>It has nothing to do with golang. My:</p>
  <pre><code>appointmentDate: selectedDay.date
  </code></pre>
  <p>What formatted as <code>2019-01-01</code> and <code>-</code> is not a valid character that can be send to the backend. It worked into my browser, but it needs to be URI encoded to be passed.</p>
  <p>So this did the trick:</p>
  <pre><code>`${cookieName}=${encodeURIComponent(cookieValue)};secure;` + &quot;path=/&quot;;`
  </code></pre>
  <p>And in go (didn't catch err here to save space):</p>
  <pre><code>cookie, _ := r.Cookie(&quot;appointment&quot;)
  data, _ := url.QueryUnescape(cookie.Value)
  </code></pre>