Skip to content

libterty/Social-Hub

Repository files navigation

🚀 Quick Start Guide - Social Go Auth Service

📋 Prerequisites

  • Go 1.21+ (you have 1.23.0 ✅)
  • MySQL 8.0+
  • Git

⚡ Quick Setup (5 minutes)

1. Install Development Tools

# Make executable and run
chmod +x install-tools.sh
./install-tools.sh

# Or install manually
go install github.com/air-verse/air@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install -tags 'mysql' github.com/golang-migrate/migrate/v4/cmd/migrate@latest

2. Database Setup

# Start MySQL (macOS with Homebrew)
brew services start mysql

# Or on Ubuntu/Debian
sudo systemctl start mysql

# Create database
mysql -u root -p -e "CREATE DATABASE social_go CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"

3. Environment Configuration

# Copy environment file
cp .env.example .env

# Edit with your settings
nano .env

Update these values in .env:

DATABASE_URL=root:YOUR_PASSWORD@tcp(localhost:3306)/social_go?charset=utf8mb4&parseTime=True&loc=Local
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production

4. Run Migrations

# Run all migrations
make migrate-up

# Check migration status
make migrate-status

5. Start the Server

# Start with hot reload (recommended for development)
make dev

# Or start normally
make run

🧪 Test the API

Health Check

curl http://localhost:8080/health

Register a User

curl -X POST http://localhost:8080/api/v1/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "password": "password123",
    "name": "Test User"
  }'

Login

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

📚 Available Commands

Server Management

make run          # Start server locally
make dev          # Start with hot reload
make build        # Build binary
make test         # Run tests
make health       # Check server status

Database & Migrations

make migrate-up           # Run all migrations
make migrate-down         # Rollback last migration
make migrate-status       # Show migration status
make migrate-create NAME=add_field  # Create new migration
make db-create           # Create database
make db-reset            # Drop, create, and migrate

Docker (Alternative Setup)

make docker-up           # Start all services with Docker
make docker-down         # Stop Docker services
make docker-logs         # View logs

Development Tools

make fmt             # Format code
make lint            # Run linter
make test-coverage   # Run tests with coverage
make clean           # Clean build artifacts

🔗 Service Endpoints

Endpoint Method Description Auth Required
/health GET Health check No
/api/v1/auth/register POST Register user No
/api/v1/auth/login POST Login user No
/api/v1/auth/refresh POST Refresh token No
/api/v1/auth/google GET Google OAuth No
/api/v1/auth/apple GET Apple OAuth No
/api/v1/profile GET Get user profile Yes
/api/v1/profile PUT Update profile Yes
/api/v1/logout POST Logout user Yes

🐛 Troubleshooting

Common Issues

1. Air tool not found:

go install github.com/air-verse/air@latest

2. Database connection failed:

  • Check MySQL is running: brew services list | grep mysql
  • Verify credentials in .env
  • Test connection: mysql -u root -p

3. Migration failed:

# Check migration status
make migrate-status

# Force to specific version if needed
make migrate-force VERSION=1

4. Port already in use:

# Find process using port 8080
lsof -i :8080

# Kill process
kill -9 <PID>

🎯 Next Steps

  1. Configure OAuth - Add your Google/Apple credentials to .env
  2. Add Features - Extend the API with new endpoints
  3. Deploy - Use Docker compose for production deployment
  4. Monitor - Add logging and monitoring

📖 Project Structure

social_go/
├── internal/
│   ├── config/         # Configuration management
│   ├── database/       # Database connection
│   ├── handlers/       # HTTP handlers
│   ├── middleware/     # HTTP middleware
│   ├── models/         # Database models
│   ├── repositories/   # Data access layer
│   ├── services/       # Business logic
│   └── utils/          # Utility functions
├── migrations/         # Database migrations
├── pkg/               # Shared packages
├── Makefile           # Development commands
└── main.go            # Application entry point

Happy coding! 🎉

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published