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
+6.7k Golang : When to use make or new?
+17.9k Golang : Login and logout a user after password verification and redirect example
+29.1k Golang : Get first few and last few characters from string
+8.6k Golang : Add text to image and get OpenCV's X, Y co-ordinates example
+19.1k Golang : Display list of time zones with GMT
+41.9k Golang : How do I convert int to uint8?
+9.1k Golang : Handle sub domain with Gin
+8.6k Golang : Progress bar with ∎ character
+8.9k Golang : GMail API create and send draft with simple upload attachment example
+19.2k Golang : Check if directory exist and create if does not exist
+19.6k Golang : Set or Add HTTP Request Headers
+9.5k Golang : Get all countries currencies code in JSON format