Sample Rest API project I made while learning some Go and Echo
This project intends to serve as a template to kickstart Go API development with Echo framework.
- Database schema and migrations with Goose
- Type-safe SQL interfaces with sqlc
- Local development setup with Docker, Docker Compose, Make
- Live reload with Air in Docker
- Very basic placeholder auth middleware with API_KEY
Setup your local environment with the following commands
# Install goose and sqlc locally
$ make setup
# Build your containers
$ make build
# Start your containers
$ make run
Then in another shell:
# Update your database schema by applying the migrations
$ make goose/migrate
$ make goose/create
- Note: this will create a file with the default name
*_rename_this_file.sql
so you may want to rename it.
$ make sqlc/generate
$ make stop
If you want to test your Docker image:
# Build your image
$ docker build -f docker/Dockerfile -t golang-echo-api .
# Replace the corresponding env vars and run it!
$ docker run -p 8000:<PORT> -e PORT=<PORT> -e DATABASE_URL=<database_url> -e API_KEY=<api_key> golang-echo-api
- If you want to use your local DB to test this build you can use host.docker.internal in your database url env var parameter (i.e.
-e DATABASE_URL=postgresql://postgres:[email protected]:5432/postgres
)
This project is licensed under the MIT License - see the LICENSE file for details.