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 :

http://golang.org/pkg/net/http/#Redirect

Advertisement