Hugo is an amazing tool to generate static websites.
Sometimes, you want to protect content from being shownm
Here’s a simple Golang application which will compile to a binary.
.First, make sure you
- Know some Linux Basics
- Have a VPS online (you can get one at Linode)
- Have installed GO locally
Golang App
func (app *application) routes() http.Handler {
router := httprouter.New()
router.NotFound = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
app.notFound(w)
})
dynamic := alice.New(app.sessionManager.LoadAndSave, noSurf, app.authenticate)
protected := dynamic.Append(app.requireAuthentication)
protectedFileServer := http.FileServer(http.Dir("./protected-content"))
// app.requireAuthentication
router.Handler(http.MethodGet, "/protected/*filepath", protected.Then(protectedFileServer))
standard := alice.New(app.recoverPanic, app.logRequest, secureHeaders)
return standard.Then(router)
}