-
-
Save xiangjian/0ea31f4e1e1e7847bfd70a882cb5441a to your computer and use it in GitHub Desktop.
Http Redirect in Golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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