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
+7.5k Golang : Gorrila set route name and get the current route name
+15.3k Golang : How to get Unix file descriptor for console and file
+41.4k Golang : Convert string to array/slice
+5.4k Golang *File points to a file or directory ?
+22.8k Golang : untar or extract tar ball archive example
+21.7k Golang : Setting up/configure AWS credentials with official aws-sdk-go
+9.2k Golang : does not implement flag.Value (missing Set method)
+6.5k Grep : How to grep for strings inside binary data
+16.9k Golang : How to generate QR codes?
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+13.9k Golang : How to check if a file is hidden?
+17.2k Golang : Find file size(disk usage) with filepath.Walk