Golang net/http.Redirect() function example
package net/http
Golang net/http.Redirect() function usage example
package main
import (
"log"
"net/http"
)
func redirect(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "http://www.golang.org", 301)
}
func main() {
http.HandleFunc("/", redirect)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
See also : https://www.socketloop.com/tutorials/golang-how-to-redirect-to-new-page-with-net-http
Reference :
Advertisement
Something interesting
Tutorials
+11.6k Golang : Simple file scaning and remove virus example
+25.3k Golang : Get current file path of a file or executable
+7.1k Nginx : How to block user agent ?
+10.2k Golang : Use regular expression to get all upper case or lower case characters example
+26.4k Golang : Get executable name behind process ID example
+12.7k Android Studio : Highlight ImageButton when pressed on example
+33.8k Golang : convert(cast) bytes to string
+12.3k Golang : Flush and close file created by os.Create and bufio.NewWriter example
+8.3k Golang : Oanda bot with Telegram and RSI example
+9.4k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+9.7k PHP : Get coordinates latitude/longitude from string
+7.5k Golang : How to stop user from directly running an executable file?