This repository contains a simple Trivia REST API built with Go, PostgreSQL, Fiber, and Docker.
Follow the steps below to set up and run the Trivia API on your local machine.
Make sure you have the following tools installed on your machine:
- Docker
- Go (1.19.0 or later)
- cmd/api/main.go: Main application entry point.
- handlers: Contains HTTP request handlers.
- models: Defines the data model for trivia facts.
- routes.go: Defines the API routes.
The API uses PostgreSQL as the database. You can access the database on localhost:5432
with the provided credentials.
- List Facts:
GET /
- Create Fact:
POST /fact
Create a .env
file in the root of the project with the following content:
DB_USER=<db-user>
DB_PASSWORD=<db-password>
DB_NAME=<db-name>
These variables are used to configure the PostgreSQL database for the Trivia API. Adjust the values according to your requirements.
git clone https://github.com/mxnuchim/golang-trivia-api.git
cd golang-trivia-api
To start the API, run the following commands:
make build # Build the Docker image
make run # Start the Docker containers and the api
- start_web: Run a bash shell in the web service container with service ports exposed.
make start_web
-
build: Build the Docker images.
make build
-
run: Start the containers.
make run