Created
March 26, 2020 12:06
-
-
Save 76creates/3d07d336e9a3f5256ffe3de9b23d9790 to your computer and use it in GitHub Desktop.
golang 302 redirection and order of things in response
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in order to do a redirection or any response including custom code/header/json body at the same time | |
// order in which they are arranged is important, one will overwrite another and you wont get proper | |
// response, bellow is the order which will allow you to set all 3 | |
// any custom header goes first | |
w.Header().Set( | |
"Location", | |
"http://localhost/something/else | |
) | |
// then status code | |
w.WriteHeader(http.StatusFound) | |
// then json body | |
json.NewEncoder(w).Encode(resp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment