How to redirect to a URL in Go

The http package in Go allows you to create an HTTP server to receive HTTP requests and redirect the client to a different URL

Redirecting to a URL in Go is quite easy through the http.Redirect() method. It takes an http.ResponseWriter, *http.Request, endpoint, and HTTP status code as arguments in that order. Here’s how to use it:

func redirectToFreshman(w http.ResponseWriter, r *http.Request) {
	endpoint := ""

	http.Redirect(w, r, endpoint, http.StatusSeeOther)

Thanks for reading, and happy coding!