Skip to content

Instantly share code, notes, and snippets.

@lzjluzijie
Created May 14, 2017 10:51
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 lzjluzijie/bdc9d0af8ab3673314e0032135a0f88c to your computer and use it in GitHub Desktop.
Save lzjluzijie/bdc9d0af8ab3673314e0032135a0f88c to your computer and use it in GitHub Desktop.
Golang HTTP Redirect
package main
import (
"log"
"net/http"
)
func redirect(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "https://halu.lu/", 302)
}
func main() {
http.HandleFunc("/", redirect)
err := http.ListenAndServe(":80", 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