Skip to content

Instantly share code, notes, and snippets.

@ii0
Forked from hSATAC/gist:5343225
Created November 1, 2016 05:45
Show Gist options
  • Save ii0/751697b29b750d6fafb1df8e23bbd430 to your computer and use it in GitHub Desktop.
Save ii0/751697b29b750d6fafb1df8e23bbd430 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