Skip to content

Instantly share code, notes, and snippets.

@xiangjian
Forked from hSATAC/gist:5343225
Created November 27, 2020 10:48
Show Gist options
  • Save xiangjian/0ea31f4e1e1e7847bfd70a882cb5441a to your computer and use it in GitHub Desktop.
Save xiangjian/0ea31f4e1e1e7847bfd70a882cb5441a to your computer and use it in GitHub Desktop.
Http Redirect in Golang
package main
import (
"log"
"net/http"
)
func redirect(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "http://www.google.com", 301)
}
func main() {
http.HandleFunc("/", redirect)
err := http.ListenAndServe(":9090", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment