GoBlog/shortDomain.go

16 lines
403 B
Go
Raw Normal View History

2020-12-24 10:00:16 +00:00
package main
import (
"net/http"
)
func (a *goBlog) redirectShortDomain(next http.Handler) http.Handler {
2020-12-24 10:00:16 +00:00
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
if a.cfg.Server.shortPublicHostname != "" && r.Host == a.cfg.Server.shortPublicHostname {
http.Redirect(rw, r, a.getFullAddress(r.RequestURI), http.StatusMovedPermanently)
2020-12-24 10:00:16 +00:00
return
}
next.ServeHTTP(rw, r)
})
}