Added redirect for media.lmika.org
This commit is contained in:
parent
62891d7c21
commit
9e28142735
31
main.go
31
main.go
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gorilla/mux"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -19,31 +18,8 @@ func main() {
|
|||
port = "8080"
|
||||
}
|
||||
|
||||
routes := []struct {
|
||||
From string
|
||||
To string
|
||||
}{
|
||||
{From: "/2022/04/a-case-for-mocking-in-unit-tests", To: "https://lmika.org/2022/04/12/a-case-for.html"},
|
||||
{From: "/2021/06/parametrising-your-bdd-tests-in-go", To: "https://www.workingset.net/development/go/parametrising-bdd-tests"},
|
||||
{From: "/2021/03/communication-among-stimulus-controllers-part-2", To: "https://lmika.org/2021/02/17/communication-among-stimulus.html"},
|
||||
{From: "/2021/02/communication-among-stimulus-controllers-part-1", To: "https://lmika.org/2021/02/17/communication-among-stimulus.html"},
|
||||
{From: "/2021/01/a-simple-source-ip-address-filter-in-go", To: "https://lmika.org/2021/01/20/a-simple-source.html"},
|
||||
{From: "/2021/01/building-sets-from-maps", To: "https://lmika.org/2021/01/09/building-sets-from.html"},
|
||||
{From: "/2020/12/test-helpers-and-test-packages-in-go", To: "https://www.workingset.net/development/go/test-helpers-and-packages"},
|
||||
{From: "/2020/12/a-tour-of-domain-records-for-email", To: "https://lmika.org/2020/12/18/a-tour-of.html"},
|
||||
{From: "/2020/12/dealing-with-errors-in-go", To: "https://lmika.org/2020/12/16/dealing-with-errors.html"},
|
||||
{From: "/2020/12/building-and-serving-go-wasm-projects", To: "https://www.workingset.net/development/go/go-and-wasm"},
|
||||
{From: "/2020/12/a-brief-look-at-stimulus", To: "https://lmika.org/2020/12/08/a-brief-look.html"},
|
||||
{From: "/2020/12/setting-go-variables-during-build", To: "https://www.workingset.net/development/go/set-variables-in-build"},
|
||||
{From: "/2020/12/posts-only-rss-feed-in-hugo", To: "https://www.workingset.net/development/web/posts-only-rss-feed-in-hugo"},
|
||||
}
|
||||
|
||||
r := mux.NewRouter()
|
||||
for _, route := range routes {
|
||||
r.Handle(route.From+"/", redirectTo(route.To))
|
||||
r.Handle(route.From, redirectTo(route.To))
|
||||
}
|
||||
r.Handle("/", redirectTo("https://lmika.org/"))
|
||||
r := http.NewServeMux()
|
||||
r.Handle("/", redirectTo("https://pub-d9610a73a30e4060aaf007864420dd0f.r2.dev"))
|
||||
|
||||
svr := http.Server{
|
||||
Addr: fmt.Sprintf(":%v", port),
|
||||
|
@ -58,6 +34,7 @@ func main() {
|
|||
|
||||
func redirectTo(url string) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, url, http.StatusPermanentRedirect)
|
||||
newURL := url + r.URL.Path
|
||||
http.Redirect(w, r, newURL, http.StatusFound)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue