I tried to start a blog for a about a half year. This was a rollercoaster of ideas and experiments.
My first idea was to create a small web server in Go. The requirements for it was :
Since I have used Go as my main language for about a year creating the server was a breez. I started small by just serving files and adding some templates. It can be boiled down to one funciton
func serveTemplate(w http.ResponseWriter, r *http.Request) {
fileName := filepath.Clean(r.URL.Path)
if fileName == "/" {
fileName = "index.html"
}
lp := filepath.Join("templates", "layout.html")
fp := filepath.Join("templates", fileName)
// Return a 404 if the template doesn't exist
info, err := os.Stat(fp)
if err != nil {
if os.IsNotExist(err) {
log.Printf("page not found : %s", fp)
http.NotFound(w, r)
return
}
}
// Return a 404 if the request is for a directory
if info.IsDir() {
http.NotFound(w, r)
return
}
tmpl, err := template.ParseFiles(lp, fp)
if err != nil {
// Log the detailed error
log.Println(err.Error())
// Return a generic "Internal Server Error" message
http.Error(w, http.StatusText(500), 500)
return
}
err = tmpl.ExecuteTemplate(w, "layout", nil)
if err != nil {
log.Println(err.Error())
http.Error(w, http.StatusText(500), 500)
}
}
Add a bit of HTML and sprinkle some CSS and you got a website with templating.
Now I had to figure out where to host it. I had a Docker image for my site. It probably doesn’t need one but I am just used to creating every new web service in docker. I got a myself a domain, launched a EC2 instance and ran my Docker image. Everything seemed nice and danndy, except I had not HTTPS which was a bummber. I could have gone the easy route of just running ngnix as a revers-proxy with SSL there, but I wanted to try some of the fancy AWS things.
Fast forward and my simple blog consists of a :
It worked great, and I had my SSL except I got a bill from AWS much larger then I expected. I wasn’t about to pay that monthly.
I had put this idea of blog in the back burner and didn’t touch it. The only thing I did was wrote down some potential places where I could host my blog. I thought about some other AWS stuff, Heroku, Netlify.
AWS has so many things that I didn’t know where to look.
I had used Heroku in the past, so I wanted to use that, but the problem is that custom domains and SSL are paid.
About netlify I knew nothing, but knew that it hosts something and it’s pretty good from what people say.
Then I ran into Hugo - static site generator. It makes static sites, that had only html/css/js and the content is written in Markdown(or other formats if you want to) which is what I wanted. And it turns out it’s easily usable in netlify. And it’s written in Go which is a plus from me.
All I had to do is pick a theme and write this post.
And here we are now. My first blog post.