mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-06-03 20:12:58 +00:00
2.9 KiB
2.9 KiB
Containr Backend Setup
Quick Start
Prerequisites
- Go 1.21+
- PostgreSQL 12+
- Redis (optional)
Environment Variables
Create a .env file or set these environment variables:
# Database
DATABASE_URL=postgres://containr:password@localhost:5432/containr?sslmode=disable
REDIS_URL=redis://localhost:6379
# Server
PORT=8080
ENVIRONMENT=development
# Security
JWT_SECRET=your-secret-key-change-in-production
# Frontend (for CORS)
FRONTEND_URL=http://localhost:3000
Database Setup
- Create PostgreSQL database:
CREATE DATABASE containr;
CREATE USER containr WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE containr TO containr;
- Run migrations (handled automatically on server start)
Running the Server
# Build
go build -o bin/server cmd/server/main.go
# Run
./bin/server
The server will start on http://localhost:8080
API Endpoints
Health Check
GET /health- Server health status
Authentication
POST /api/v1/auth/login- User loginPOST /api/v1/auth/register- User registration
User Profile
GET /api/v1/user/profile- Get user profile (requires auth)PUT /api/v1/user/profile- Update user profile (requires auth)
Projects
GET /api/v1/projects- List user projects (requires auth)POST /api/v1/projects- Create project (requires auth)GET /api/v1/projects/:id- Get project details (requires auth)PUT /api/v1/projects/:id- Update project (requires auth)DELETE /api/v1/projects/:id- Delete project (requires auth)
Authentication
Include JWT token in Authorization header:
Authorization: Bearer <your-jwt-token>
Example Usage
- Register a user:
curl -X POST http://localhost:8080/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "password123",
"name": "Test User"
}'
- Login:
curl -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "password123"
}'
- Create a project (using token from login):
curl -X POST http://localhost:8080/api/v1/projects \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"name": "My Project",
"description": "A test project"
}'
Development
Project Structure
cmd/server/ - Main application entry point
internal/
├── api/ - HTTP handlers and routes
├── config/ - Configuration management
├── database/ - Database connections and migrations
└── middleware/ - HTTP middleware
migrations/ - SQL migration files
Adding New Endpoints
- Create handler functions in
internal/api/ - Add routes in
internal/api/routes.go - Update database schema if needed in
migrations/