Created
September 27, 2017 23:30
-
-
Save harshavardhana/a135fafff0d97b31b25ee303ebf28d46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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