Skip to content

dmasior/service-go

Repository files navigation

Service-Go

This is a Go web service starter-kit consisting of an HTTP server and a worker processing background tasks. It's not based on a framework but a few easy replaceable libraries.

Service-Go promotes an API-first development approach using the OpenAPI specification as the source of truth. Development workflow:

  1. Update the API spec
  2. Run make generate to generate server stubs
  3. Implement business logic in the generated handlers, and write tests

Features

  • Basic structure
    • Config values loaded from .env
    • Logging setup slog
  • API HTTP server
  • Background worker with simple task queue
  • Database setup
    • PostgreSQL with sqlc for type-safe SQL. Can be replaced with SQLite, MySQL
    • Migrations
  • Example user signup and signin flow
    • Password hashing, JWT-based auth
  • Worker task creation via API and background processing
  • Integration tests
    • Signin, signup, task creation
    • Task processing
    • Separate db per test
    • Fixtures
  • Metrics and observability
  • CI/CD pipeline

Getting started

After cloning the repository, copy .env.example to .env

cp .env.example .env

Start the dependencies

make start-deps

Run the CMDs locally using your IDE for the best development and debug experience. But, you can also use:

make run-api
make run-worker

Request examples

Signup:

curl --location 'http://localhost:8080/v1/signup' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "[email protected]",
    "password": "password",
    "captcha": "test-captcha"
}'

SignIn:

curl --location 'http://localhost:8080/v1/signin' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "[email protected]",
    "password": "password",
    "captcha": "test-captcha"
}'

Open api spec in https://editor.swagger.io to see the API docs.

Running tests

make test