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
+7k Golang : Find the shortest line of text example
+10.9k Nginx : TLS 1.2 support
+8.4k Golang : How to check if input string is a word?
+19.3k Golang : Calculate entire request body length during run time
+28k Golang : Move file to another directory
+24.5k Golang : How to validate URL the right way
+7.7k Golang : Mapping Iban to Dunging alphabets
+7.7k Golang : Error reading timestamp with GORM or SQL driver
+6.1k Java : Human readable password generator
+16.4k Golang : Convert slice to array
+7.8k Golang : Load DSA public key from file example