I used to use Wordpress to write my blog. But I recently think of creating the blog system by Golang and make it for fun. Here is what I am doing now. The main reason I start doing is that I found the markdown support in Wordpress is slightly weird and hard to use. When I try to change some blog content, the markdown style sometimes won’t show correctly. That makes me feel frustrated. I think that probably might because I am using the free plan in wordpress.com and have less control of my blog.
So, my goal is quite simple and straightforward. The new blog should fully support markdown content. And it should serve a clean and straightforward interface. Let’s see how I am going to do it.
Due to the two goals above, here I choose to create it from scratch. I choose to use Go-Gin and Blackfriday to build the blog system.
Do it
Go Gin
Gin is an HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance – up to 40 times faster.
Blackfriday
Blackfriday: a markdown processor for Go.
These two libraries give me enough abilities to build the blog system.
The first step, create your blog folders with two sub-folder, markdowns, and templates. Markdowns folder is for your blog content post. Templates folder is for the HTML template, which we load posts list and content into an HTML page.
<!DOCTYPE html> <htmllang="en"> <head> <metacharset="utf-8"/> <metahttp-equiv="X-UA-Compatible"content="IE=edge"/> <metaname="viewport"content="width=device-width, initial-scale=1"/> <title>We've got some trouble | 404 - Resource not found</title> <linkhref="dark_theme.css"rel="stylesheet"type="text/css"/> </head> <body> <divclass="cover"> <h1>Resource not found <small>Error 404</small> </h1> <pclass="lead">The requested resource could not be found but may be available again in the future. <ahref="/">Go back now!</a></p></div> <footer><p>Technical Contact: <ahref="wang.chauyan@gmail.com">e-mail me</a></p></footer> </body> </html>
Gin would load these template files into our primary function. Let’s take a look of the main.go source code here.
Let’s check the main function first. We have 4 steps to run this blog system:
initServer to initialize the Gin engine to get the instance back. In the meantime, we also tell Gin how we load the templates and use actions.
setupRootAPI to set up how to react with users access your homepage entry point.
setupPostAPI to set up how to send back the selected post content back to the user.
server.Run to run up the server-side.
It’s pretty straightforward and easy to understand. I think the next step I would need to have the theme support in this simple blog system like Ghost Themes. You can find the whole project in my Github repo - Mini blog system in Go
I used to use Wordpress to write my blog. But I recently think of creating the blog system by Golang and make it for fun. Here is what I am doing now. The main reason I start doing is that I found the markdown support in Wordpress is slightly weird and hard to use. When I try to change some blog content, the markdown style sometimes won’t show correctly. That makes me feel frustrated. I think that probably might because I am using the free plan in wordpress.com and have less control of my blog.
So, my goal is quite simple and straightforward. The new blog should fully support markdown content. And it should serve a clean and straightforward interface. Let’s see how I am going to do it.
Due to the two goals above, here I choose to create it from scratch. I choose to use Go-Gin and Blackfriday to build the blog system.
Do it
Go Gin
Gin is an HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance – up to 40 times faster.
Blackfriday
Blackfriday: a markdown processor for Go.
These two libraries give me enough abilities to build the blog system.
The first step, create your blog folders with two sub-folder, markdowns, and templates. Markdowns folder is for your blog content post. Templates folder is for the HTML template, which we load posts list and content into an HTML page.
<!DOCTYPE html> <htmllang="en"> <head> <metacharset="utf-8"/> <metahttp-equiv="X-UA-Compatible"content="IE=edge"/> <metaname="viewport"content="width=device-width, initial-scale=1"/> <title>We've got some trouble | 404 - Resource not found</title> <linkhref="dark_theme.css"rel="stylesheet"type="text/css"/> </head> <body> <divclass="cover"> <h1>Resource not found <small>Error 404</small> </h1> <pclass="lead">The requested resource could not be found but may be available again in the future. <ahref="/">Go back now!</a></p></div> <footer><p>Technical Contact: <ahref="wang.chauyan@gmail.com">e-mail me</a></p></footer> </body> </html>
Gin would load these template files into our primary function. Let’s take a look of the main.go source code here.
Let’s check the main function first. We have 4 steps to run this blog system:
initServer to initialize the Gin engine to get the instance back. In the meantime, we also tell Gin how we load the templates and use actions.
setupRootAPI to set up how to react with users access your homepage entry point.
setupPostAPI to set up how to send back the selected post content back to the user.
server.Run to run up the server-side.
It’s pretty straightforward and easy to understand. I think the next step I would need to have the theme support in this simple blog system like Ghost Themes. You can find the whole project in my Github repo - Mini blog system in Go