form post 로 받아서 DB로 조회하고 성공시, 어떻게 다른 링크로 돌려보내나 고민을 했는데
http.Redirect()라는 함수를 발견. StatusSeeOther는 303 코드인데 좀.. 생소하네?
if r.Method == "POST" { saveChoice(r.Form["choices"]) http.Redirect(w, r, newUrl, http.StatusSeeOther) } |
[링크 : https://stackoverflow.com/questions/35934298/how-to-redirect-to-a-url]
특이하게도.. Response와 Request 둘다 들어와야 쓸 수 있는 녀석.
func Redirect(w ResponseWriter, r *Request, url string, code int) Redirect replies to the request with a redirect to url, which may be a path relative to the request path. The provided code should be in the 3xx range and is usually StatusMovedPermanently, StatusFound or StatusSeeOther. If the Content-Type header has not been set, Redirect sets it to "text/html; charset=utf-8" and writes a small HTML body. Setting the Content-Type header to any value, including nil, disables that behavior. |
'Programming > golang' 카테고리의 다른 글
golang https server (0) | 2022.09.05 |
---|---|
golang 쿠키 (0) | 2022.09.02 |
golang html form post 처리하기 (0) | 2022.09.02 |
golang http.HandleFunc(pattern) (0) | 2022.08.31 |
golang mariadb 연동 (0) | 2022.08.30 |