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:
- Update the API spec
- Run
make generate
to generate server stubs - Implement business logic in the generated handlers, and write tests
- Basic structure
- Config values loaded from .env
- Logging setup slog
- API HTTP server
- Router chi, paths generated from openapi v3 spec using oapi-codegen
- Server auth middleware
- 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
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
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.
make test