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
+9.7k Golang : Sort and reverse sort a slice of floats
+8.2k Golang : Add build version and other information in executables
+21.2k Golang : How to force compile or remove object files first before rebuild?
+4.7k Javascript : Access JSON data example
+9.1k Golang : Handle sub domain with Gin
+19.5k Golang : Example for DSA(Digital Signature Algorithm) package functions
+25.5k Golang : Generate MD5 checksum of a file
+8.2k Golang : Reverse text lines or flip line order example
+16.8k Golang : Get own process identifier
+41.9k Golang : How do I convert int to uint8?
+22.4k Golang : How to read JPG(JPEG), GIF and PNG files ?