Skip to content

PeterM45/go-postgres-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go PostgreSQL Auth API

Simple, lightweight authentication system built with Go and PostgreSQL.

Prerequisites

  • Go 1.19+
  • Docker and Docker Compose

Quick Start

  1. Clone and setup
git clone https://github.com/PeterM45/go-postgres-api
cd go-postgres-api
  1. Create .env file
DB_USER=admin
DB_PASS=password
DB_NAME=myapp
DB_HOST=localhost
DB_PORT=5433
PORT=8080
JWT_SECRET=your-secret-key
  1. Run
# Start PostgreSQL
docker compose up -d

# Run API
go run cmd/main.go

API Routes

Public

  • POST /api/users - Create user
  • POST /api/auth/login - Login

Protected (Requires JWT)

  • GET /api/users - List users
  • GET /api/users/{id} - Get user
  • PUT /api/users/{id} - Update user
  • DELETE /api/users/{id} - Delete user

Test with curl

# Create user
curl -X POST http://localhost:8080/api/users \
-H "Content-Type: application/json" \
-d '{"username": "test", "email": "[email protected]", "password": "password123"}'

# Login
curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]", "password": "password123"}'

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages