title: Cookie does not set using Golang
body: <p>I have a REST API for login a user which sets a cookie on the browser for logged-in user and its working well.
  The problem is when I want to call login API when user completed their registration from signup API, so that time every thing working well but cookie doesn't set to browser.</p>
  
  <p>Here is login API:</p>
  
  <pre><code>var loginViaDjangoApiShim = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  
          var t loginPost
          var oldCookieToken string
  
          decoder := json.NewDecoder(r.Body)
          _:= decoder.Decode(&amp;t)
          expiration := time.Now().Add(365 * 24 * time.Hour)
  
          flagToReturn, cookie, _:= postToApiShim(t.Username, t.Password)
          if flagToReturn == "pass" {
              CookieToken = generateOldCookie(authIdFromUserName.ID)
  
              newCookieToSet := http.Cookie{Name: "ddagyeog", Value: CookieToken , Expires: expiration, Domain: COOKIE_DOMAIN, Path: "/", Secure: false, HttpOnly: true}
              http.SetCookie(w, &amp;newCookieToSet)
          }
          returnValues := returnLoginFlag{Flag: flagToReturn, Cookie: ""}
          json.NewEncoder(w).Encode(returnValues)
  
      })
  </code></pre>
  
  <p>And here registration API:</p>
  
  <pre><code>var signUpStart = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  
      var t StartFlowPost
  
      decoder := json.NewDecoder(r.Body)
      _:= decoder.Decode(&amp;t)
          insertIntoUser := InsertMethod(t)
              flag, _ := loginOnCoppaAndNonCoppaUsersSignup(t.UserName, t.Password)
  
          log.Println(flag)
          json.NewEncoder(w).Encode(flag)
  
  })
  </code></pre>
  
  <p>And below is <code>loginOnCoppaAndNonCoppaUsersSignup</code> which calls login API after signup user.</p>
  
  <pre><code>func loginOnCoppaAndNonCoppaUsersSignup(userName, password string) (flag returnSignUpFlagCoppa, err error) {
      var loginFlag returnLoginFlag
      var jsonStr = []byte(`{
      "username":"` + userName + `",
      "password":"` + password + `"
      }`)
  
      request, _ := http.NewRequest("POST", USER_ROOT_URL+"login", bytes.NewBuffer(jsonStr))
      request.Header.Set("Content-Type", "application/json")
  
      client := &amp;http.Client{}
      response, _:= client.Do(request)
  
      decoder := json.NewDecoder(response.Body)
      if err = decoder.Decode(&amp;loginFlag); err != nil {
          return flag, err
      }
  
      if loginFlag.Flag == "pass" {
          flag = returnSignUpFlagCoppa{Flag: "pass", Username: userName}
          log.Println(flag)
      } else {
          flag := returnSignUpFlagCoppa{Flag: "error"}
          log.Println(flag)
      }
  
      return flag, nil
  }
  </code></pre>