Skip to content

Repository files navigation

Go web server

A high-performance HTTP server written in Go featuring a modern blog system with markdown support, server-side template rendering, and embedded assets.

This project demonstrates best practices for building scalable web applications in Go, including middleware chain implementation, configuration management, and full-featured content management capabilities.

The server serves HTML views, static assets, and a comprehensive API surface with pagination support for blog content.

Quickstart

Requirements:

  • Go 1.26+

Build:

make build

Run:

make run

Configuration

This project supports .env file (loaded automatically) and a few command-line flags.

  • Environment file: copy .env.example.env and edit values.
  • Flags (highest priority):
    • -host (default 0.0.0.0)
    • -port (default 8000)
    • -resources (path served at /resources/ for large files)
    • -serve (addional path served at /)
    • -version (prints binary version)

.env variables (examples in .env.example): HOST, PORT ...

Embedded assets

blog/, views/, static/, and public/ are embedded into the binary via assets.go. The server always serves those embedded files at runtime; to change the content, edit the files under their respective folders and rebuild the binary.

Routes

  • GET / - home page with latest 5 blog posts (paginated)
  • GET /blog/ - blog listing page with latest 10 posts (paginated)
  • GET /blog/{date}/{slug} - individual blog post page
  • GET /* - additional path served at / route set by -serve
  • GET /* - public assets served at / route
  • GET /static/* - static assets
  • GET /health - health check (JSON)
  • GET /ready - readiness check (JSON)
  • GET /resources/* - served from the path set by -resources
  • GET /robots.txt

Templates

Templates are located in views/ and include:

  • layout.html — base layout
  • meta.html — PWA/meta includes
  • home.html — home page with latest 5 blog posts
  • about.html - simple about page
  • blog_list.html — blog listing page
  • blog_post.html — individual blog post page
  • not_found.html — 404 error page

Blog System

This server includes a full-featured blog system with markdown support and YAML frontmatter.

Creating Blog Posts

Blog posts are markdown files located in the blog/ directory with optional YAML frontmatter:

---
title: My Post Title
excerpt: A short summary of the post
author: Author Name
license: CC BY-SA
createdAt: 2024-01-15
keywords: [tag1, tag2, tag3]
---
Your markdown content here...

Frontmatter Fields

  • slug — URL-friendly identifier (defaults to filename without .md)
  • title — Post heading (defaults to slug in Title Case)
  • excerpt — Short summary (defaults to first 160 characters of content)
  • author — Single author string or array of authors (defaults to "Anonymous")
  • license — Content license (defaults to "CC BY-SA")
  • createdAt — Publication date (defaults to file creation time)
  • updatedAt — Update date (defaults to file modification time)
  • published — Draft/live status, boolean (defaults to true)
  • keywords — Comma-separated tags for SEO (optional)
  • image — Featured image URL/path (optional)
  • image_alt — Alt text for featured image (optional)
  • reading_time — Auto-calculated from word count, not manually specified

Markdown Features

Blog posts support advanced markdown features via GFM extensions:

  • Tables
  • Strikethrough
  • Task lists
  • Footnotes
  • Definition lists
  • Auto-linking
  • Typographic enhancements
  • Auto-generated heading IDs for anchor links

Reading time is automatically calculated based on word count.

License

MIT License

About

go lang web server

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages