← BACK TO ENGLISH

Hugo Protected Content Go

Date: 26 August 2024 | Updated: 26 August 2024

26 August 2024 | 5 min read

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)
}

Need something like this?

I build high-performance Go-based software and websites which I can host for you on a $5 Linux VPS. No intermediate agency layers, direct developer execution.

Discuss an Integration →

Andrei PrivacyZen Newsletter

Liked the article? join Andrei's PrivacyZen Newsletter. Topics include wellbeing, privacy, life, programming, and cybersecurity.