❤️ Uptrace.dev - distributed traces, logs, and errors in one place
This project implements JSON API as specified in RealWorld spec. It was created to demonstrate how to use:
- treemux HTTP router.
- go-pg PostgreSQL client and ORM.
- Caching using Redis.
- Rate limiting using Redis.
- go-pg/migrations.
- Tracing using uptrace-go.
Your can find some details about design principles in the Writing REST API with Go and PostgreSQL tutorial.
Project consists of the following packages:
- rwe global package parses configs, establishes DB connections etc.
- org package manages users and tokens.
- blog package manages articles and comments.
- app folder contains application resources such as config.
- cmd/api runs HTTP server with JSON API.
- cmd/migrate_db command that runs SQL migrations.
The most interesting part for go-pg users is probably article filter.
First of all you need to create a config file changing defaults as needed:
cp app/config/dev.yml.default app/config/dev.yml
Project comes with a Makefile
that contains following recipes:
make db_reset
drops existing database and creates a new one.make test
runs unit tests.make api_test
runs API tests provided by RealWorld.
After checking that tests are passing you can start API HTTP server:
go run cmd/api/*.go -env=dev