Skip to content

Instantly share code, notes, and snippets.

@harshavardhana
Created September 27, 2017 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshavardhana/a135fafff0d97b31b25ee303ebf28d46 to your computer and use it in GitHub Desktop.
Save harshavardhana/a135fafff0d97b31b25ee303ebf28d46 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"net/http"
"strings"
)
func RedirectHandler(code int) http.Handler {
return &redirectHandler{code}
}
// Redirect to a fixed URL
type redirectHandler struct {
code int
}
func (rh *redirectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
u := *r.URL
if strings.HasPrefix(r.URL.Path, "/bucket1") {
u.Host = "m3.minio.io:9001"
http.Redirect(w, r, u.String(), rh.code)
} else if strings.HasPrefix(r.URL.Path, "/bucket2") {
u.Host = "m3.minio.io:9002"
http.Redirect(w, r, u.String(), rh.code)
}
}
func main() {
log.Println("Listening on 0.0.0.0:9000")
log.Fatalln(http.ListenAndServe(":9000", RedirectHandler(301)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment