Skip to content

Instantly share code, notes, and snippets.

@mlehner616
Forked from hSATAC/gist:5343225
Created July 15, 2017 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlehner616/98b6227a20e76aa6705ac8c24f954d62 to your computer and use it in GitHub Desktop.
Save mlehner616/98b6227a20e76aa6705ac8c24f954d62 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