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
+8k Golang : What fmt.Println() can do and println() cannot do
+38.1k Golang : Read a text file and replace certain words
+7.8k Golang : Scan files for certain pattern and rename part of the files
+13.9k Golang : How to determine if a year is leap year?
+29.2k Golang : missing Git command
+9.8k Golang : Format strings to SEO friendly URL example
+27.4k Golang : Convert CSV data to JSON format and save to file
+13.7k Golang : Check if an integer is negative or positive
+14.2k Elastic Search : Mapping date format and sort by date
+5.5k Golang : Display advertisement images or strings on random order
+10.2k Golang : Text file editor (accept input from screen and save to file)
+29.4k Golang : JQuery AJAX post data to server and send data back to client example