Skip to content

A Go-based web service that exposes user-related endpoints (status, leaderboard, task completion, referral assignment) backed by PostgreSQL. The project uses Gin for HTTP routing and pgx for database access.

Notifications You must be signed in to change notification settings

AlmetovKamil/simple-http-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple HTTP Server

A Go-based web service that exposes user-related endpoints (status, leaderboard, task completion, referral assignment) backed by PostgreSQL. The project uses Gin for HTTP routing and pgx for database access.

Features

  • Retrieve user status with balance and profile information.
  • View a leaderboard of users sorted by balance with optional limit/offset.
  • Mark user tasks as completed and return updated task metadata.
  • Assign a referrer to a user while enforcing validation rules (self-referral, duplicates, missing users).

Project Structure

cmd/api             # Application entry point
internal/adapter    # HTTP handlers, routing, and PostgreSQL repository implementation
internal/core       # Domain models, use cases, and repository ports
migrations          # SQL migrations for users/tasks tables and seed data

Requirements

  • Go 1.24+
  • Docker and Docker Compose (optional but recommended)
  • PostgreSQL (Docker setup provided)
  • golang-migrate CLI if running migrations locally

Environment Variables

Create a .env file (sample used by Docker Compose):

POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=simple_http_server
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
APP_DB_DSN=postgres://postgres:postgres@postgres:5432/simple_http_server?sslmode=disable

Adjust credentials/hostnames as needed for your environment.

Run with Docker Compose

docker compose up --build

This starts:

  1. postgres – PostgreSQL 17 with persistence via pgdata volume.
  2. migrate – Applies SQL migrations on startup.
  3. app – Gin server compiled with Delve debugger support (ports 8080 for HTTP, 40000 for DAP).

The API becomes available at http://localhost:8080 once migrations finish and the app starts.

Local Development (without Docker)

  1. Ensure PostgreSQL is running and migrations are applied via migrate CLI:
    migrate -path migrations -database "$APP_DB_DSN" up
  2. Export APP_DB_DSN to match your database.
  3. Run the server:
    go run ./cmd/api

API Overview

  • GET /users/:id/status – Fetch user profile and balance.
  • GET /users/leaderboard?limit=&offset= – List users sorted by balance.
  • POST /users/:id/task/complete – Body { "task_id": number }; marks the task as done.
  • POST /users/:id/referrer – Body { "referrer_id": number }; assigns a referrer.

Responses follow JSON structures defined in internal/core/usecase DTOs. Errors are mapped to HTTP status codes via internal/adapter/http/user_handler.go.

About

A Go-based web service that exposes user-related endpoints (status, leaderboard, task completion, referral assignment) backed by PostgreSQL. The project uses Gin for HTTP routing and pgx for database access.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published