realworld.go

command module
v0.0.0-...-ee9832a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 17 Imported by: 0

README

realworld.go

.github/workflows/build.yaml
Minimalistic http server template in go that is:

  • Small (less than 300 lines of code)
  • Single file
  • Only standard library dependencies

Not a framework, but a starting point for building HTTP services in Go.

Inspired by Mat Ryer & earthboundkid and even kickstart.nvim

Features

  • Graceful shutdown: Handles SIGINT and SIGTERM signals to shutdown gracefully.
  • Health endpoint: Returns the server's health status including version and revision.
  • OpenAPI endpoint: Serves an OpenAPI specification.
  • Debug information: Provides various debug metrics including pprof and expvars.
  • Access logging: Logs request details including latency, method, path, status, and bytes written.
  • Panic recovery: Catch and log panics in HTTP handlers gracefully.
  • Fully documented: Includes comments and documentation for all exported functions and types.

Getting started

  • Use this template to create a new repository
  • Or fork the repository and make changes to suit your needs.
Requirements

Go 1.22 or later

Suggested Dependencies
Build and run the server
$ make run 
  • this will build the server and run it on port 8080
  • Checkout Makefile for more

Endpoints

  • GET /health: Returns the health of the service, including version, revision, and modification status.
  • GET /openapi.yaml: Returns the OpenAPI specification of the service.
  • GET /debug/pprof: Returns the pprof debug information.
  • GET /debug/vars: Returns the expvars debug information.

How to

How to start a new project
  • Use this template to create a new repository
  • Or fork the repository and make changes to suit your needs.
  • Find and replace all strings raeperd/kickstart.go with your repository/image name
How to remove all comments from the code
$ sed -i '' '/^\/\/go:embed/! {/^\s*\/\/.*$/d; /^\s*\/\*\*/,/\*\//d;}' *.go

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL